What’s new in 2.6
Driver Team Lead, Node.js driver, MongoDB INC
Christian Kvalheim
#mongodb
Me
• Driver Team Lead
• Node.js driver developer
• @christkv
• http://www.christiankvalheim.com
Agenda
• Aggregation Cursors
• maxTimeMS
• New or Enhanced update operations
• New Security Model
• Ordered/Unordered Bulk Operations
• Background index building on secondaries
• parallelCollectionScan command
Aggregation Cursors
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);!}!
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!}!
Aggregation Cursors
• Cursor id is just a normal MongoDB cursor meaning it works like other cursors using the wire protocol call getMore.
maxTimeMS
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)!
New or Enhanced update operations
New or Enhanced update operations
• $mul
• $bit
• $min/$max
• $currentDate
• $push enhancements
$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);!
$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);!
$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);!
$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}));!
$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}));!
New Security Model
New Security Model
• Now with
• Roles
• Rights
• You can customize the roles and rights to your liking.
• Subscription Edition also includes
• LDAP
• X509 authentication
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 }!})!
Ordered/Unordered Bulk Operations
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);!
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
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
Background index building on secondaries
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
parallelCollectionScan command
parallelCollectionScan command
• Split collection into multiple cursors
• Read in parallel from the collection
• No matching semantics (it’s for pure dumping purposes only)
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);!
Thank You
Driver Team Lead, Node.js driver, MongoDB INC
Christian Kvalheim
#mongodb
Top Related