With a MongoDB collection structure as in this example:
{
"_id" : "123",
"memberinfo" : [{
"height": 170,
"weight": 55,
"status": "approved",
"fruits" : [ {"name" : "apple","reason" : null },
{"name" : "orange","reason" : null},
{"name" : "berry","reason" : null}
],
}]
},
{
"_id" : "456",
"memberinfo" : [{
"height" : 160,
"weight": 90,
"status": "approved",
"fruits" : [ {"name" : "berry","reason" : null},
{"name" : "orange","reason" : null}
],
},{
"height" : 160,
"weight": 90,
"status": "rejected",
"fruits" : [ {"name" : "banana","reason" : null}
],
}]
}
How is it possible to query the nested array to get the memberinfo which has the status:approved.
The result should be like this:
{
"_id" : "123",
"memberinfo" : [{
"height": 170,
"weight": 55,
"status": "approved",
"fruits" : [ {"name" : "apple","reason" : null },
{"name" : "orange","reason" : null},
{"name" : "berry","reason" : null}
],
}]
},
{
"_id" : "456",
"memberinfo" : [{
"height" : 160,
"weight": 90,
"status": "approved",
"fruits" : [ {"name" : "berry","reason" : null},
{"name" : "orange","reason" : null}
],
}]
}
I tried this but the result is not right:
IMongoQuery query = Query.And(Query.EQ("memberinfo.status", "approved"));
MongoCursor mongocursor = nsdb.GetCollection(DBPrefix, "Member").Find(query);
BsonDocumentBsonDocumentis equivalent forkey valuepair. Example{"key":"value"}in C# written asnew BsonDocument { { "key", "value" } }