Hi,
I’m new to MongoDB and I’ve been struggling with this for a day now. Any examples I’ve found refuse to work for me.
My documents are ExpandoObject that have a number of array properties. The array properties are BsonDocument arrays, although they could be arrays of known-types - I’ve tried both methods without success. Here’s how they look in the DB at the moment:
I’ve proved that I can find a document by id and by filtering on another field:
var filter =
Builders<ExpandoObject>.Filter.Eq("_id", id) &
Builders<ExpandoObject>.Filter.Eq("Status", 4);
But when I include an array property in the filter and use the recommended ElemMatch, I cannot fetch the record. I’ve tried a few variations of the following to include the array filter:
var filter =
Builders<ExpandoObject>.Filter.Eq("_id", id) &
Builders<ExpandoObject>.Filter.ElemMatch("CtoRatings", Builders<BsonDocument>.Filter.Eq("UserId", 175));
I want to be able to update properties on these arrays, but first I want to fetch a record.
var item = (await collection.FindAsync<ExpandoObject>(filter)).FirstOrDefault();
Can anyone see where I’m going wrong?
Thanks