user1828605
user1828605

Reputation: 1735

How to retrieve all the values of field in mongodb?

Here's an example of collection I have in 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. 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.

Upvotes: 0

Views: 77

Answers (1)

CesarTrigo
CesarTrigo

Reputation: 433

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"
    }
]
}

Upvotes: 2

Related Questions