craiggwilson/fluent-mongo — Issue #47: OR clause syntax error
Author: jberd126
Created: 2012-01-18 23:28:18+00:00
State: open

Thanks for supporting the FluentMongo project, it's much appreciated. I ran into the following issue however.

When I have this query:

IQueryable
query = database.GetCollection
("items").AsQueryable()
.Where(e => e.DateTimes.Any(dt =>
(dt.Begin <= begin && dt.End > begin) ||
(dt.Begin >= begin && dt.Begin < end)) &&
mappings.Keys.Contains(e.MapId));

The generated native Mongo query is invalid:

{ "dateTimes" : { "$elemMatch" : { "$or" : { "begin" : { "$lte" : ISODate("2012-01-05T07:00:00Z"), "$gte" : ISODate("2012-01-05T07:00:00Z"), "$lt" : ISODate("2012-01-06T07:00:00Z") }, "end" : { "$gt" : ISODate("2012-01-06T07:00:00Z") } } } },
"mapId" : { "$in" : [10036, 45733, 72018] } }

Resulting in the error:

Mongo query appears to be invalid. Error:
QueryFailure flag was $and/$or/$nor must be a nonempty array (response was { "$err" : "$and/$or/$nor must be a nonempty array", "code" : 13086 }).

The native Mongo query is missing opening JSON array demarcations surrounding 'or' clause:

... { "$or" : [ { "begin" : ...