New in MongoDB 2.6

1,256 views

Published on

What's the cool new features coming in 2.6.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,256
On SlideShare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

New in MongoDB 2.6

  1. 1. What’s new in 2.6 DriverTeam Lead,Node.js driver,MongoDB INC Christian Kvalheim #mongodb
  2. 2. Me • Driver Team Lead • Node.js driver developer • @christkv • http://www.christiankvalheim.com
  3. 3. Agenda • Aggregation Cursors • maxTimeMS • New or Enhanced update operations • New Security Model • Ordered/Unordered Bulk Operations • Background index building on secondaries • parallelCollectionScan command
  4. 4. Aggregation Cursors
  5. 5. 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);! }!
  6. 6. 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! }!
  7. 7. Aggregation Cursors • Cursor id is just a normal MongoDB cursor meaning it works like other cursors using the wire protocol call getMore.
  8. 8. maxTimeMS
  9. 9. 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)!
  10. 10. New or Enhanced update operations
  11. 11. New or Enhanced update operations • $mul • $bit • $min/$max • $currentDate • $push enhancements
  12. 12. $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);!
  13. 13. $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);!
  14. 14. $min/$max var 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);!
  15. 15. $currentDate var 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}));!
  16. 16. $push enhancements var 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}));!
  17. 17. New Security Model
  18. 18. New Security Model • Now with • Roles • Rights • You can customize the roles and rights to your liking. • Subscription Edition also includes • LDAP • X509 authentication
  19. 19. New Security Model - Create Role Ex var 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 }! })!
  20. 20. Ordered/Unordered Bulk Operations
  21. 21. Ordered/Unordered Bulk Operations var 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);!
  22. 22. Ordered/Unordered Bulk Operations • New BulkAPI 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
  23. 23. 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
  24. 24. Background index building on secondaries
  25. 25. 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
  26. 26. parallelCollectionScan command
  27. 27. parallelCollectionScan command • Split collection into multiple cursors • Read in parallel from the collection • No matching semantics (it’s for pure dumping purposes only)
  28. 28. parallelCollectionScan command var 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);!
  29. 29. ThankYou DriverTeam Lead,Node.js driver,MongoDB INC Christian Kvalheim #mongodb

×