1

In every document i have some field (for example "myfield"). myfield is value of type int32.

Please show me (with tiny code example) how to make query like:

"get all where myfield > 10 and myfield < 20"

I am using an official C# driver.

Thank you very much!!!

2 Answers 2

14

Following code example search for documents in 'someDb' in 'someCollection' where myfield > 10 and < 20 :

var server = MongoServer.Create("mongodb://localhost:27020");
var database = server.GetDatabase("someDb");

var collection = database.GetCollection<Type>("someCollection");
var searchQuery = Query.GT("myfield", 10).LT(20);
var list = collection.Find(searchQuery);

But be sure that you have run mongodb on 27020 port.

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

Comments

0

With criteria is

Expression<Func<T, bool>> criteria;

You can use this:

collection.Remove(Query<T>.Where(criteria));

Comments

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.