New in MongoDB 2.6
-
Upload
christkv -
Category
Technology
-
view
542 -
download
2
description
Transcript of New in MongoDB 2.6
![Page 1: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/1.jpg)
What’s new in 2.6
Driver Team Lead, Node.js driver, MongoDB INC
Christian Kvalheim
#mongodb
![Page 2: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/2.jpg)
Me
• Driver Team Lead
• Node.js driver developer
• @christkv
• http://www.christiankvalheim.com
![Page 3: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/3.jpg)
Agenda
• Aggregation Cursors
• maxTimeMS
• New or Enhanced update operations
• New Security Model
• Ordered/Unordered Bulk Operations
• Background index building on secondaries
• parallelCollectionScan command
![Page 4: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/4.jpg)
Aggregation Cursors
![Page 5: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/5.jpg)
Aggregation Cursors
• Aggregation framework can now return a cursor
var test = db.getSisterDB('test');!test.t.drop();!!for(var i = 0; i < 100; i++) {! db.t.insert({a:i});!}!!var c = test.t.aggregate([{$match: {}}], {cursor: { batchSize:1 }});!!while(c.hasNext()) {! print(c.next().a);!}!
![Page 6: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/6.jpg)
Aggregation Cursors• You can control the behavior of the aggregation cursor
passing in the cursor option with the batchSize> db.runCommand({aggregate: "t", pipeline: [], cursor: {batchSize: 1}!! , allowDiskUse: true})!{!! "cursor" : {!! ! "id" : NumberLong("39465949628"),!! ! "ns" : "test.t",!! ! "firstBatch" : [!! ! ! {!! ! ! ! "_id" : ObjectId("532808ea4be168cc8e9dd7dd"),!! ! ! ! "a" : 0!! ! ! }!! ! ]!! },!! "ok" : 1!}!
![Page 7: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/7.jpg)
Aggregation Cursors
• Cursor id is just a normal MongoDB cursor meaning it works like other cursors using the wire protocol call getMore.
![Page 8: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/8.jpg)
maxTimeMS
![Page 9: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/9.jpg)
maxTimeMS
• Ever wanted to set a specific query or command timeout ?
• maxTimeMS is what you’ve been looking for.
> db.t.find({"$where": "sleep(1000)"}).maxTimeMS(50)!
![Page 10: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/10.jpg)
New or Enhanced update operations
![Page 11: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/11.jpg)
New or Enhanced update operations
• $mul
• $bit
• $min/$max
• $currentDate
• $push enhancements
![Page 12: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/12.jpg)
$mul
var test = db.getSisterDB('test');!test.t.drop();!!db.t.insert({ _id: 1, item: "ABC", price: 10.99 });!!db.t.update({ _id: 1 },! { $mul: { price: 1.25 } });!!print(db.t.findOne({_id:1}).price);!
![Page 13: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/13.jpg)
$bit
• supports and/or/xor (xor is new)
var test = db.getSisterDB('test');!test.t.drop();!!db.t.insert({ _id: 1, expdata: NumberLong(1) });!!db.t.update({ _id: 1 },! { $bit: { expdata: { xor: NumberInt(5) } } })!!print(db.t.findOne({_id:1}).expdata);!
![Page 14: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/14.jpg)
$min/$maxvar test = db.getSisterDB('test');!test.t.drop();!!db.t.insert({ _id: 1, desc: "crafts", ! dateEntered: ISODate("2013-10-01T05:00:00Z"),! dateExpired: ISODate("2013-10-01T16:38:16Z")!});!!db.t.update({ _id: 1 }, {! $min: { dateEntered: new Date("2013-09-25") }!})!!print(db.t.findOne({_id:1}).dateEntered);!
![Page 15: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/15.jpg)
$currentDatevar test = db.getSisterDB('test');!test.t.drop();!!db.t.insert({ _id: 1, !! status: "a", !! lastModified: ISODate("2013-10-02T01:11:18.965Z") });!!db.t.update({ _id: 1 }, {!! $currentDate: {!! ! lastModified: true,!! ! lastModifiedTS: { $type: "timestamp" }},!! $set: { status: "D" }!});!!printjson(db.t.findOne({_id:1}));!
![Page 16: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/16.jpg)
$push enhancementsvar test = db.getSisterDB('test');!test.t.drop();!!db.t.insert({ "_id" : 1, "scores" : [50,60,70,100 ]});!!db.t.update({ _id: 1 }, !! { $push: { scores: {!! ! ! $each: [ 20, 30 ],!! ! ! $position: 2!! ! }!! }!});!!printjson(db.t.findOne({_id:1}));!
![Page 17: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/17.jpg)
New Security Model
![Page 18: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/18.jpg)
New Security Model
• Now with
• Roles
• Rights
• You can customize the roles and rights to your liking.
• Subscription Edition also includes
• LDAP
• X509 authentication
![Page 19: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/19.jpg)
New Security Model - Create Role Exvar admin = db.getSisterDB('admin');!admin.createRole({! role: "myClusterwideAdmin",! privileges:! [! { resource: { cluster: true }, ! ! actions: [ "addShard" ] },! { resource: { db: "config", collection: "" }, ! ! actions: [ "find", "update", "insert" ] },! { resource: { db: "users", collection: "usersCollection" }, ! ! actions: [ "update" ] },! { resource: { db: "", collection: "" }, ! ! actions: [ "find" ] }! ],! roles:! [! { role: "read", db: "admin" }! ],! writeConcern: { w: "majority" , wtimeout: 5000 }!})!
![Page 20: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/20.jpg)
Ordered/Unordered Bulk Operations
![Page 21: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/21.jpg)
Ordered/Unordered Bulk Operationsvar test = db.getSisterDB('test');!test.t.drop();!!var bulk = db.t.initializeOrderedBulkOp();!bulk.insert({a:1});!bulk.find({a:1}).update({$set: {b:1}});!bulk.find({a:2}).upsert().update({$set: {b:1}});!bulk.find({a:1}).remove();!var result = bulk.execute({w:1});!printjson(result);!
![Page 22: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/22.jpg)
Ordered/Unordered Bulk Operations
• New Bulk API shared across drivers and shell
• Uses new write Commands underneath the covers
• Splits up documents into batches
• Write Commands is the future of writing for MongoDB
• w:0 semantics is no result details when using write commands
![Page 23: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/23.jpg)
Ordered/Unordered Bulk Operations
• Ordered
• Execute all operations in the order they where entered and fail on first write error
• Guarantees order of execution
• Unordered
• Executes all operations out of order and potentially in parallel. Does not stop on error.
• Does not Guarantee order of execution
![Page 24: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/24.jpg)
Background index building on secondaries
![Page 25: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/25.jpg)
Background index building on secondaries
• Previously only available on primary
• Could cause secondaries to hang
• Was not practical in many situations
• Secondaries can now build indexes in background
• Can also restart partially build indexes on instance termination and restart
![Page 26: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/26.jpg)
parallelCollectionScan command
![Page 27: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/27.jpg)
parallelCollectionScan command
• Split collection into multiple cursors
• Read in parallel from the collection
• No matching semantics (it’s for pure dumping purposes only)
![Page 28: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/28.jpg)
parallelCollectionScan commandvar test = db.getSisterDB('test');!test.t.drop();!!var bulk = db.t.initializeOrderedBulkOp();!for(var i = 0; i < 100000; i++) {!! bulk.insert({a:i});!};!!var result = bulk.execute({w:1});!result = test.runCommand({!! ! parallelCollectionScan: 't'!! ,! numCursors: 4!});!!printjson(result);!
![Page 29: New in MongoDB 2.6](https://reader034.fdocuments.us/reader034/viewer/2022052310/54922cf9ac795939288b46dc/html5/thumbnails/29.jpg)
Thank You
Driver Team Lead, Node.js driver, MongoDB INC
Christian Kvalheim
#mongodb