这是我在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"
}
当从Twitter检索时,该集合被转储到mongodb集合。现在,我想为其他位置添加更多数据。由于这是我第一次使用mongodb,我无法弄清楚如何只检索位置字段。
答案 0 :(得分:2)
使用带有空或过滤查询的投影:
db.collectionName.find({},{locations:1})
将检索这样的内容:
{
"_id" : ObjectId("5407a0a9b7a33063850f5b09"),
"locations" : [
{
"woeid" : 1,
"name" : "Worldwide"
}
]
}