Suppose you can read the JSON string accordingly. For example, you read the first JSON text
{ "test_id" : 1245362, "name" : "ganesh", "age" : "28", "Job" :
{"company name" : "company1", "designation" : "SSE" }
}
and assign it to a variable (String json1), the next step is to parse it,
DBObject dbo = (DBObject) com.mongodb.util.JSON.parse(json1);
put all dbo in the list,
List<DBObject> list = new ArrayList<>();
list.add(dbo);
:
new MongoClient().getDB("test").getCollection("collection").insert(list);
EDIT:
MongoDB Documents DBObject, -. :
:
import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
( EDIT):
Document doc = Document.parse(json1);
new MongoClient().getDataBase("db").getCollection("collection").insertOne(doc);
.
new MongoClient().getDataBase("db").getCollection("collection").insertMany(list);
, . :
db.collection.find()
mongo, , :
{ "_id" : ObjectId("56a0d2ddbc7c512984be5d97"),
"test_id" : 1245362, "name" : "ganesh", "age" : "28", "Job" :
{ "company name" : "company1", "designation" : "SSE"
}
}
, .