1

I have a collection "foo":

db.foo.insert({a:[1, 10]})
db.foo.insert({a:[4, 6]})


and a query:

db.foo.find({a: {$elemMatch: {$gte: 5, $lte: 7}}})

and result is:

{a: [4, 6]}

My question is how to use Query.ElemMatch() in this situation?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
suco2007
  • 131
  • 1
  • 7
  • This link might help you http://stackoverflow.com/questions/6266994/how-can-i-and-multiple-elemmatch-clauses-with-c-sharp-and-mongodb – cubbuk Jan 08 '13 at 18:34

2 Answers2

2

You can use C#'s collection initializer syntax to clean it up a bit:

Query.ElemMatch("a", new QueryDocument {
    {"$gte", 5}, 
    {"$lte", 7}
})
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
1

I found a solution for my problem and hope it's useful for someone

Query.ElemMatch("a", Query.And(new QueryDocument("$gte", 5), new QueryDocument("$lte", 7)))
suco2007
  • 131
  • 1
  • 7