this is the find({})
query,
[ { state:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
... 4020 more items ] } ]
this is my schema,
var state_schema= mongoose.Schema({
state:[
{
id: String,
name: String,
country_id: String
}
]
});
this is the object;
{
"id" : "2624",
"name" : "Boaco",
"country_id" : "158",
"_id" : ObjectId("59f95fb9180e291fcc90683b")
},
i need to get all objects wich have the country_id
"158". i cant get it,
this is what i tried..
1. state.find({state:{"$in":[{country_id:req.body.country_code}]}},{_id:0, __v:0}
this results an empty array.
2. state.find({state: {$elemMatch: {country_id: req.body.country_code}}},{_id:0,__v:0}
here i am getting all the results, which means filtering is not working (results simple find({})).
3. state.find({'state.rooms': {country_id: req.body.username}}, function (err,state)
here also []
empty array returns.
how to do this?