On Github mcascallares / mongo-2.6-new-features-presentation
db.createRole( { role: "myClusterWideAdmin", privileges: [], roles: [] } );
db.grantPrivilegesToRole("myClusterWideAdmin", [
{resource: { cluster : true}, actions : ["addShard"]},
{resource: { db: "test", collection: ""}, actions : ["enableSharding"]}
]);
db.articles.ensureIndex( { a : "text" } );
db.articles.insert( { a : "the quick brown fox jumped over the lazy dog" } );
db.articles.find( { $text : { $search : "quickly" } } );
# specify language for the search
db.articles.find( { $text : { $search: "quickly", $language : "fr" } } );
# sort results by score
db.articles.find(
{ $text: { $search: "bake coffee cake" } }, // predicate
{ score : { $meta : "textScore" } } // projection
).sort( { score: { $meta: "textScore" } } )
# output the score
db.articles.find(
{ $text:{ $search : "quickly", $language : "fr" } },
{ score : { $meta : "textScore" } }
);
db.foo.ensureIndex( { a:1 } );
db.foo.ensureIndex( { b:1 } );
db.foo.find( {a:123, b:456} );
// using a cursor
db.foo.aggregate( [
{ $match : { } }, // pipeline
{ cursor : { batchSize : 1 } }
});
// output to a collection
db.test.aggregate([
{ $match : { } }, // pipeline
{ $out : "my_output_collection" } );
// using text search inside the pipeline
db.articles.aggregate( [
{ $match : { $text : { $search : "chien", $language : "fr" }}}
]);
{ a : 1 } + { $mul : { a : 10 } } -> { a : 10 }
{ a : 1 } + { $min : { a : 100}} -> { a : 1} // no op
{ $currentDate : { dt : true } } -> {dt: new Date()}
db.products.insert([
{ item: "pencil", qty: 50, type: "no.2" },
{ item: "pen", qty: 20 },
{ item: "eraser", qty: 25}
]);
// this change requires wire protocol changes!!!
// expensive query with regex without anchor
db.foo.find( { description : /August [0-9]+ 1969/ } ).maxTimeMS(100)
// it works with aggregation framework
db.articles.aggregate( [
{ $match : { $text : { $search : "chien", $language : "fr" }}}
]).maxTimeMS(100)