Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb query constructor to take raw query string Java

I am trying to come up with a concept to take a query string and have it passed into something like this via a query object:

returnList = mongoTemplateTracking.find(query,TrackingData.class, COLLECTION_NAME);

I've been looking at the constructors of both the Query and Criteria classes to see if they could take a raw string such as:

 "ID" : "32399a"

Instead of building up the Criteria object via Criteria.where().is() etc..

I have seen the method

protected <T> List<T> doFind(String collectionName,
                 com.mongodb.DBObject query,
                 com.mongodb.DBObject fields,
                 Class<T> entityClass)

However as I am autowiring the mongoTemplateTracking into my class I cannot access this method.

like image 546
Will Avatar asked Jun 28 '26 17:06

Will


1 Answers

JSON.parse(json) was deprecated. use this code:

String s = "{\"$or\": [ {\"name\": \"buzz\"}, {\"age\": {\"$lt\": 20 }} ] }";
Bson bson =  BasicDBObject.parse( json );
collection.find(bson);
like image 168
HungNM2 Avatar answered Jul 01 '26 10:07

HungNM2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!