使用例子如下
插入和查询
#
db.collectionName.insertOne(
<document or array of documents>
)
# 插入students collection,查看db内的collection
db.students.insertOne(
{
"name": "nick",
"age": 12
}
)
show collections
# 基本查询
db.collectionName.find(<query>,[projection])
db.students.find()
db.collectionName.insertMany(
[<document 1>,<document 2>]
)
db.posts.insertMany(
[{"msg": "hello","id": 1},{"msg": "wwww","id": 1},{"msg": "hello","age": 1}]
)
db.posts.find()
db.posts.find({})
db.posts.find({"age": 1})
# 找一个结果
db.posts.findOne({"age": 1})
# 投影查询,只显示age
db.posts.find({"age": 1},{"age": 1})
更新
db.collectionName.update(query,update,option)
//
网友评论