0

How can I query for all tags in following document in mongoDB 2 or 3:

{
    "_id" : ObjectId("55dc45017137a4e70b8b4569"),
    "campainName" : "",
    "themeName" : "theme1",
    "emailListName" : "eiEmails",
    "emailSubject" : "",
    "emailFrom" : "",
    "allNews" : [ 
        {
            "type" : "1",
            "tag" : ['aa','bb','cc'],
            "link" : "",
            "image" : ""
        }
    ]
},
{
    "_id" : ObjectId("55dc45017137a4e70b8b4570"),
    "campainName" : "",
    "themeName" : "theme2",
    "emailListName" : "afaeiEmails",
    "emailSubject" : "",
    "emailFrom" : "",
    "allNews" : [ 
        {
            "type" : "1",
            "tag" : ['da','db','dc'],
            "link" : "",
            "image" : ""
        }
    ]
}

I need something like this in result:

{['aa','bb','cc'], ['da','db','dc']}

I need style of query in doctrine odm.

Community
  • 1
  • 1

1 Answers1

1

Try something like this:

db.collection.find({}, {"allNews.tag" : 1, _id : 0})

evanchooly
  • 6,102
  • 1
  • 16
  • 23
  • it will get you this: `{ "allNews": [ { "tag": [ "aa", "bb", "cc" ] } ] } { "allNews": [ { "tag": [ "da", "db", "dc" ] } ] }` Which is probably as close as you'll get without using an aggregation pipeline. – evanchooly Aug 25 '15 at 13:17
  • the answer is correct for this document http://paste.ubuntu.com/12192513/ not for question's document. allNews is a list. – Majid safaei Aug 25 '15 at 13:20