2

I am new to java. How can I build this mongo query in java. Any help/hint will be appreciated.

db.places.find({loc : { $near :[ -122.934326171875,37.795268017578] , $maxDistance : 50 } ,$or:[{"uid":"at"},{"myList.$id" :ObjectId("4fdeaeeede2d298262bb80") } ] ,"searchTag" : { $regex : "Union", $options: "i"} } );
1
  • what you have tried uptil now to implement it. Can you show us ? Commented Aug 17, 2012 at 8:17

1 Answer 1

6

By using the QueryBuilder you can create the query you wanted. I have created it as follows.

QueryBuilder query = new QueryBuilder();
query.put("loc").near(-122.934326171875, 37.795268017578, 50);
query.or(
        QueryBuilder.start("uid").is("at").get(),
        QueryBuilder.start("myList.$id").is(new ObjectId("5024f2f577a59dd9736ddc38")).get()
            );
query.put("searchTag").regex(Pattern.compile("Union",Pattern.CASE_INSENSITIVE));

When I print the query into the console it looks like :

{ "loc" : { "$near" : [ -122.934326171875 , 37.795268017578 , 50.0]} , 
  "$or" : [ { "uid" : "at"} , { "myList.$id" : { "$oid" : "5024f2f577a59dd9736ddc38"}}] , 
  "searchTag" : { "$regex" : "Union" , "$options" : "i"}
}

I didn't try it but hope it will work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your response. Let me try and get back to you.

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.