[英]How to retrieve all the values of field in mongodb?
Here's an example of collection I have in Mongodb 这是我在Mongodb中收集的示例
{
"_id":ObjectId("54076c79f764e4ea431bf7f6"),
"trends":[
{
"query":"%23Ces aroni",
"name":"#Cesaroni",
"url":"http://twitter.com/search?q=%23Cesaroni",
"promoted_content":null
},
{
"query":"%23MelihG%C3%B6kcekKKy%C4%B1De%C5%9Fi freEdiyor",
"name":"#MelihGökcekKKyiDesifreEdiyor",
"url":"http://twitter.co m/search?q=%23MelihG%C3%B6kcekKKy%C4%B1De%C5%9FifreEdiyor",
"promoted_content":null
},
{
"query":"%23EngvNor",
"name":"#EngvNor",
"url":"http://twitter. com/search?q=%23EngvNor",
"promoted_content":null
},
"locations":[
{
"woeid":1,
"name":"Worldwide"
}
],
"created_at":"2014-09-03T19:23:55Z",
"as_of":"2014-09-03T19:31:05Z"
}
The collection is dumped to mongodb collection as it is retrieved from Twitter. 该集合将从Twitter检索到时转储到mongodb集合。 Now, I want to add more data for other locations. 现在,我想为其他位置添加更多数据。 Since this is the first time I'm using mongodb, I couldn't figure out how I can retrieve just the locations field. 由于这是我第一次使用mongodb,因此我无法弄清楚如何仅检索locations字段。
Use projection with an empty or filtered query: 将投影与空查询或过滤查询一起使用:
db.collectionName.find({},{locations:1})
Will retrieve something like this: 将检索如下内容:
{
"_id" : ObjectId("5407a0a9b7a33063850f5b09"),
"locations" : [
{
"woeid" : 1,
"name" : "Worldwide"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.