danyolgiax
danyolgiax

Reputation: 13086

Lambda syntax in MongoDb driver to update an array element in a document

I'm using MongoDb C# driver in my application and I need to update a sub-item in my document. I found the way doing something like this:

var query = Query<User>.ElemMatch(_=>_.Item, qb=>qb.EQ(x => x.Valid,false));

var update = Update.Set("Item.$.Valid", true); <-- can I use lambda here?

var result = collection.Update(query, update);

Now I want to ask you: Can I use lambda syntax to remove the fixed string "Item.$.Valid" enabling compile-time check (like Update<Item>.Set(x=>x...)?

Inside driver source code I've found nothing about this!

Upvotes: 2

Views: 970

Answers (1)

Craig Wilson
Craig Wilson

Reputation: 12624

Not right now. This is the JIRA ticket for it. https://jira.mongodb.org/browse/CSHARP-588

Coming up with a good syntax for this without doubling all the helper methods is difficult. We are completely open to suggestions, so please comment on the JIRA ticket if you have some.

Upvotes: 2

Related Questions