MongoDB中怎么操作集合数据
更新:HHH   时间:2023-1-7


这篇文章给大家介绍MongoDB中怎么操作集合数据,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

1.查看已有集合

show collections

2.向集合中添加数据

db.runoob.insert({

title:'test',

description:'this is description',

by:'suyanzhu',

url:'https://blog.51cto.com/suyanzhu',

tags:['php','java','mongodb'],

likes:100

})

3.查看集合中数据信息

db.runoob.find()

4.通过定义变量存储数据信息,再添加到runoob集合中

document=({

        "title" : "demo",

        "description" : "this is description",

        "by" : "yansuzhu",

        "url" : "https://blog.51cto.com/suyanzhu",

        "tags" : [

                "php",

                "sql",

                "java"

        ],

        "likes" : "100"

})

db.runoob.insert(document)

//或

db.runoob.save(document)

关于MongoDB中怎么操作集合数据就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

返回MongoDB数据库教程...