0

I'm trying to use the collection.FindAndModify and give it a IMongoQuery which selects all the documents. But I can not find how to create a query without any conditions!

Can anyone tell me how to do this? I'm using MongoDB C# Driver v1.8.3.

Here's my code:

var query = ???;
var sortBy = SortBy.Ascending(new string[] { "last_update" });
var update = Update<Entity>.Set(e => e.last_update, DateTime.Now);
var fields = Fields.Include(new string[] { "counter", "_id" });
var m = collection.FindAndModify(query, sortBy, update, fields, false, false);

I wonder what should I write in place of ??? to select all the documents!?

1 Answer 1

1

Use an empty QueryDocument:

var query = new QueryDocument();

But keep in mind that FindAndModify will only modify the first matching document.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, and the thing about FindAndModify I knew that and it is wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.