Edward83
Edward83

Reputation: 6686

MongoDB C# Query expression (How to?)

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!!!

Upvotes: 1

Views: 12580

Answers (2)

Thanh Tung
Thanh Tung

Reputation: 105

With criteria is

Expression<Func<T, bool>> criteria;

You can use this:

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

Upvotes: 0

Andrew Orsich
Andrew Orsich

Reputation: 53695

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.

Upvotes: 14

Related Questions