Re: Converting Mongo OR query to Java language query

57 views
Skip to first unread message

Sid

unread,
Oct 12, 2012, 4:42:19 PM10/12/12
to mongodb-user
Something like this should work :

ArrayList orList = new ArrayList();

orList.add(new BasicDBObject("WORD", "NICE"));
orList.add(new BasicDBObject("WORD", "HAPPY"));
orList.add(new BasicDBObject("WORD", "BAD"));

BasicDBObject query = new BasicDBObject("$or", orList);


On Oct 12, 11:23 am, Christopher Carver <christopher.car...@gmail.com>
wrote:
> I have the following MongoDB query that I need to convert to Java language.
>
> db.someCollection.count( { $or :  [ { 'WORD' : 'NICE' } , { 'WORD' :
> 'HAPPY' } , { 'WORD' : 'BAD' } ] } );
>
> I'm stuck on how to stipulate the the OR condition as an array in the
> BasicDBObject. Not sure what the proper approach for this.
>
> BasicDBObject cond1 = new BasicDBObject( "WORD", "NICE" );
>
> BasicDBObject cond2 = new BasicDBObject( "WORD", "HAPPY" );
>
> BasicDBObject cond3 = new BasicDBObject( "WORD", "BAD" );
>
> BasicDBObject query = new BasicDBObject();
>
> query.put("$or", ???? );
Reply all
Reply to author
Forward
0 new messages