美文网首页
三、mogodb文档的增删改查

三、mogodb文档的增删改查

作者: Nick_4438 | 来源:发表于2023-02-28 21:12 被阅读0次

使用例子如下

插入和查询

# 
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)
//

删除

相关文章

网友评论

      本文标题:三、mogodb文档的增删改查

      本文链接:https://www.haomeiwen.com/subject/yjalldtx.html