I have a users collection whose schema is as follow :
var userSchema = new mongoose.Schema({
id : Number,
tags :
[
{
tag_name : String,
tag_url : String,
posts :
[
{
post_id: String
}
]
}
]
});
What I would like to do is retrieving only tag_name whose post_id value is in the posts array. So, I tried query as follow
db.users.find({'tags.posts.post_id':'000000'}, {'tags.tag_name':1})
Unfortunatelly, I got all tag_name although post_id is not in posts array.
Can you help me to write query for this?
Edit =================================================================
Let's say I have data as follow :
tags
[
{
tag_name: 'java',
posts : [{post_id:'000000'}, {post_id:'111111'}
},
{
tag_name: 'ruby',
posts : [{post_id:'000000'}, {post_id:'111111'}
},
{
tag_name: 'php',
posts : [{post_id:'111111'}
},
]
I want to have tag element by post_id, if I search by post_id is '000000' I want to get only tag elements whose tag_name is 'java' and 'ruby' not the last tag element, is it possible?