1

When performing the following code

    JSONObject jSONObject = new JSONObject();
        MongoClient mongo = new MongoClient(mongoip, mongoport);
            DB db = mongo.getDB(mongodb);

            DBCollection collection = db.getCollection("abc");
            query = new BasicDBObject();
            query.put("_id", new ObjectId(recordID));
            dbObj = collection.findOne(query);

            JSONObject output = new JSONObject(JSON.serialize(dbObj));

                                        jSONObject.put("data", output);
                res = jSONObject.toString();
    return res;

I am getting this response:

data {
  "_id":{"$oid":"5c90bc4c32ef32622181d86b"},
  "created_at":"2019-03-19 03:24:20",
  "updated_at":"2019-03-19 03:33:40",
  "Temp":"30",
  "Oil":"60",
  "test":"123"
}

But i don't want $oid in response, I want response like this:

data {
  "_id":"5c90bc4c32ef32622181d86b",
  "created_at":"2019-03-19 03:24:20",
  "updated_at":"2019-03-19 03:33:40",
  "Temp":"30",
  "Oil":"60",
  "test":"123"
}

Please help me getting response like this. What should i do?

Sonal
  • 345
  • 1
  • 4
  • 8
  • It is representing ObjectId. You don't worry about it. If you want it as string you must convert to string. – Ashwanth Madhav Mar 19 '19 at 11:39
  • It is in string only. I don't want this seperate {"$oid":"5c90bc4c32ef32622181d86b"} in response.As i mentioned i want response like that.Please help me regarding that. – Sonal Mar 19 '19 at 12:47

0 Answers0