[ad_1]
I have created a mongodb collection where the schema is as follows.
{user_id, listings: <Array of Documents>, ...}
In the listing documents I have a field named status which has two values publish and draft.
In mongo shell I am trying to bring back only the user listings with status:publish
So I run the bellow command and I keep getting back also documents with status:draft that are part of the user with published listings.
db.properties.find({'listings.status':'publish'},{'listings.status':1, _id:0})
Outputs:
[
{ listings: [ { status: 'publish' } ] },
{ listings: [ { status: 'publish' } ] },
{ listings: [ { status: 'draft' }, { status: 'publish' }, { status: 'draft' } ] },
{ listings: [ { status: 'publish' }, { status: 'draft' } ] },
{ listings: [ { status: 'publish' } ] }
]
How can I get an array back of the listings with only status: publish ?
[ad_2]