Is there a way to return only the property value in the mongodb projection? For example, I have a document that has a property whose value is an array. I want the returned object from the request to be only an array, not property: [ .. ]. Example:
Document
db.test.insert({ name: "Andrew",
attributes: [ { title: "Happy"},
{ title: "Sad" }
]
});
Query:
db.test.find({name: "Andrew"},{attributes:1, "_id":0});
This returns:
{ "attributes" : [ { "title" : "Happy" }, { "title" : "Sad" } ] }
I want it to return to an array:
[ { title: "Happy"},
{ title: "Sad" }
]
Is there any way to do this? Thanks
source
share