How To Query A Dictionary on MongoDB
I have the following class
public class Group {
[BsonId]
public ObjectID _id {get; set;}
[BsonElement("Me")]
public Members Dictionary<ObjectId, UserGroupProperties> Members {get; set;}
}
How Do I query on Member开发者_如何学Cs property? Where Memebres.ObjectId == objectid? Thanks!
MongoDB has a "dot notation" for reaching into sub-objects or arrays.
Normally, the query will look something like the following:
Query.EQ("Me._id", objectid)
And will find data of this structure:
{
_id: ObjectId(),
me: [
{ _id: ObjectId(): { UserGroupProperties } },
{ _id: ObjectId(): { other UserGroupProperties } }
]
}
However, it looks like your data structure is a little different. Is your data like the following?
{
_id: ObjectId(),
me: {
ObjectId(): { UserGroupProperties },
ObjectId(): { other UserGroupProperties }
}
}
If so, then you're looking for the existence of "me.objectid". Which is different.
The big thing to note here is that MongoDB will return the entire matched document. So if you're looking for a single UserGroupProperties
your query is going to return the entire Group
.
It is reslove now.
You can check it here: MongoDb Jira
or
Blog Post of Dan Harman
精彩评论