Using JSON with MongoDB?

前端 未结 4 408
南旧
南旧 2020-12-13 15:18

My application uses JSON objects a lot (org.json.JSONArray and friends). What\'s the most efficient way to store these into Mongo DBObjects so they can be queried? BasicDBOb

4条回答
  •  猫巷女王i
    2020-12-13 15:50

    com.mongodb.util.JSON has a method to parse a JSON string into DBObject. The default JSONCallback will return a BasicDBObject or BasicDBList according to input string.

    Object jsonObj = ...; //any of your org.json objects
    Object o = com.mongodb.util.JSON.parse(jsonObj.toString());
    DBObject dbObj = (DBObject) o;
    

提交回复
热议问题