How to execute MongoDB native query (JSON) using mongo-java-driver only?

前端 未结 4 1255
南方客
南方客 2020-12-18 07:12

How to fire mongo native queries using java-mongo-driver only.

No Spring-Data or EclipseLink or Hibernate OGM, Only using

4条回答
  •  悲哀的现实
    2020-12-18 07:50

    @aaronwang4love You can try below code. Not tested. Don't have access to environment now. Please update if it works.

    BasicDBObject query = BasicDBObject.parse("{userId: {$gt: \"1\"}}"); 
    FindIterable dumps = crapCollection.find(query);
    


    OR You can Also use com.mongodb.util.JSON

    DBObject dbObject = (DBObject)JSON.parse("{userId: {$gt: \"1\"}}");
    

提交回复
热议问题