1.查看集合 show collections2.向集合中添加数据 db.runoob.insertMany([ { 'title':'data1', 'u
1.查看集合
show collections
2.向集合中添加数据
db.runoob.insertMany([
{
'title':'data1',
'url':'https://blog.51cto.com/suyanzhu',
'description':'this is data1',
'view':5000
},
{
'title':'data2',
'url':'Https://blog.51cto.com/suyanzhu',
'description':'this is data2',
'view':3650
},
{
'title':'data3',
'url':'https://blog.51cto.com/suyanzhu',
'description':'this is data3',
'view':9527
}
])
3.查看数据
db.runoob.find().pretty()
4.指定返回键(注意,只能全1或全0)
db.runoob.find({'view':{$gt:5000}},{title:1,view:1}).pretty()
5.无查询条件参数
db.runoob.find({},{title:1,view:1}).pretty()
6.不返回_id,url,description键
db.runoob.find({},{_id:0,url:0,description:0}).pretty()
--结束END--
本文标题: MongoDB查询返回指定键
本文链接: https://www.lsjlt.com/news/35142.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0