Monday, June 13, 2011

MongoDB C# Driver, Querying multiple fields with intervals

Simple way of chaining together a query when looking for records that require both field one and field two to be in a certain interval.
double foo = 1.0;
double bar = 2.0;
MongoCollection<BsonDocument> items = db.GetCollection<BsonDocument>("collection");
var query = Query.And(
    (Query.GT("field_one", foo).LT(bar)),
    (Query.GT("field_two", foo).LT(bar))
MongoCursor<BsonDocument> dbResult = items.Find(query)

No comments:

Post a Comment