Two ors

36 views
Skip to first unread message

Maciej Bąk

unread,
Sep 5, 2014, 3:41:24 AM9/5/14
to rogue...@googlegroups.com

Hi,

In mongo is possible to write query with two or's like:

db.someCollection.find({ $or : [ { "system" : "test1" } , { "system" : "test2" } ] , 
$or : [ { "something" : true } , { "something" : false } , { "something" : { $exists : false } }]
})

( I know that this specific query could be wrote in one or but I have much much more complicated query and I need to user or parameter two times ).

But lift rogue when compiling shows me and error:

Query must be HasNoOrClause, but it's actually com.foursquare.rogue.Unselected with com.foursquare.rogue.ShardKeyNotSpecified with com.foursquare.rogue.Unordered with com.foursquare.rogue.Unskipped with com.foursquare.rogue.Unlimited with com.foursquare.rogue.HasOrClause

is it possible in lift rogue write such query ?
Thanks!

Jason Liszka

unread,
Sep 5, 2014, 11:11:46 AM9/5/14
to rogue...@googlegroups.com
MongoDB doesn't support this, no. In particular it's not valid JSON, with the same key "$or" appearing twice in the document. You'll have to use demorgan's to refactor this into a single $or clause.


--
You received this message because you are subscribed to the Google Groups "rogue-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rogue-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maciej Bąk

unread,
Sep 5, 2014, 3:24:30 PM9/5/14
to rogue...@googlegroups.com
How mongo doesnt support ? I have even posted mongo query with two ors ...

db.someCollection.find({ $or : [ { "system" : "test1" } , { "system" : "test2" } ] , 
$or : [ { "something" : true } , { "something" : false } , { "something" : { $exists : false } }]
})

and its working fine.

Jason Liszka

unread,
Sep 10, 2014, 4:41:13 PM9/10/14
to rogue...@googlegroups.com
Oh, OK. The mongo shell supports it, but the mongo java driver (which rogue uses to send queries to mongo) does not. The driver's DBObjectBuilder stores keys and values in a Map, so duplicate keys will overwrite existing entries.
Reply all
Reply to author
Forward
0 new messages