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", ???? );