mongodb常见关键字应用

2012-11-16 12:03 来源:www.chinab4c.com 作者:admin

??? mongodb常见关键字应用

db.inventory.find({ $and: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )
db.collection.update( { field: value }, { $addToSet: { field: value1 } } );
db.inventory.find( { tags: { $all: [ "appliances", "school", "book" ] } } )
db.collection.update( { field: value }, { $addToSet: { field: { $each : [ value1, value2, value3 ] } } }

);

db.b.save({id:2,sex:1,info:{tel:1,add:2}})
db.b.find({info:{$elemMatch:{tel:1,add:2}}})
?db.b.find({sex:{$exists:true}})
?db.b.find({sex:{$exists:true,$in:[33,22]}})
db.collection.find().explain()

db.inventory.find( { qty: { $gt: 20 } } )
db.inventory.update( { "carrier.fee": { $gt: 2 } }, { $set: { price: 9.99 } } )

db.collection.update( { age: 20 }, { $inc: { age: 1 } } );
db.collection.update( { name: "John" }, { $inc: { age: 1 } } );

db.collection.find( { field: $regex: /acme.*corp/i, $nin: [ 'acmeblahcorp' } );

db.inventory.find( { qty: { $mod: [ 4, 3 ] } } )
db.b.update({id:1},{$rename:{sex:"sex1"}})
修改字段名称
db.collection.update( { field: value1 }, { $unset: { field1: "" } } );
db.collection.find().sort( { age: -1 } )

?