Reputation: 327
When I modified my filter to only select an ArtistDocument
whose artist_ID
contains a match in the artistIds
array, I get the following error.
"The expression tree is not supported: {document}{artist_ID}" System.Exception {System.NotSupportedException}
// array.
string[] artistsIds = new string[] { "123ABC", "456XYZ" };
// filter.
var filter = Builders<ArtistsDocument>.Filter.Where(p => p.artist_ID.Any(b => artistsIds.Contains(b.ToString())));
filter = filter & Builders<ArtistsDocument>.Filter.Eq("genre", "Rock");
filter = filter & Builders<ArtistsDocument>.Filter.Lt(x => x.transactionDate, DateTime.Now.AddSeconds(Math.Abs(30) * (-1)));
// update.
var update = Builders<ArtistsDocument>.Update.Set("status", "Processing");
// options.
var options = new FindOneAndUpdateOptions<ArtistsDocument>
{
Sort = Builders<ArtistsDocument>.Sort.Ascending(x => x.fileName).Ascending(x => x.priority),
ReturnDocument = ReturnDocument.After
};
// document.
var doc = await artistsCollection.FindOneAndUpdateAsync(filter, update, options);
Upvotes: 1
Views: 2508
Reputation: 2772
I believe you can achieve what you want with ElemMatch
Builders<ArtistsDocument>.Filter.ElemMatch
something like this:
var elemMatchFilter = Builders<YourModel>
.Filter
.ElemMatch(x => x.YourArray, x => x.ArrayField1 == field1 && x.x.ArrayField2 == field2);
Upvotes: 1