db.customers.find().pretty();數(shù)據(jù)的查詢
操作符
$set
?添加一個參數(shù)
db.customers.update({first_name:'John'},{$set:{age:1}})
匹配所有John的參數(shù)修改
db.customers.update({first_name:'John'},{$set:{age:1}},{multi:true})
$inc 設(shè)置增量
db.customers.update({first_name:'John'},{$inc:{age:12}})
$unset 刪除某個字段
db.customers.update({first_name:'John'},{$unset:{age:1}})
upsert:沒有找到?Mary 的情況追加一條數(shù)據(jù)
db.customers.update({first_name:'Mary'},{first_name:'Mary',age:12},{upsert:true})
$rename 參數(shù)名的重命名
db.customers.update({first_name:'Mary'},{$rename:"first_name":"name"} )
justOne:為true刪除一個默認(rèn)全部
db.customers.remove({first_name:'Steven'},{justOne:true} )
or:查詢條件
db.customers.find($or:[{first_name:'Steven'},{first_name:'Mary'} ])
(>)大于 - $gt(<)小于 - $lt(>=)大于等于 - $gte(<= )小于等于 - $lte
db.customers.find(age:{$lt:40})