0

I want to run a query, which returns all elements of a collection, in which

  1. the fields wasProposed and markedByUser are true and
  2. the field recipientEmail is either [email protected] or [email protected].

In my Java code, I create a BasicDBObject, whose toString returns this:

{ 
    "wasProposed" : true , 
    "recipientEmail" : 
    { 
        "$or" : 
            [ 
                { "recipientEmail" : "[email protected]" } , 
                { "recipientEmail" : "[email protected]" }
            ]
    }, 
    "markedByUser" : true
}

When I run this query (rcoll.find(query).sort(sortclause).limit(ITEMS_TO_SHOW)), I get the error com.mongodb.MongoException: invalid operator: $or.

How can I modify the query above in order to get rid of this error?

1 Answer 1

1

It's probably cleaner to use $in here instead of an $or:

{ 
    "wasProposed" : true , 
    "recipientEmail" : { "$in" : ["[email protected]", "[email protected]"] },
    "markedByUser" : true
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.