三、mogodb文档的增删改查

使用例子如下

插入和查询

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

删除

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容