Insert DBObject into MongoDB using Spring Data

后端 未结 3 1130
暖寄归人
暖寄归人 2021-02-15 16:11

I tried to insert the following DBObject into MongoDB using Spring Data:

    BasicDBObject document = new BasicDBObject();
    document.put(\"country\", \"us\");         


        
3条回答
  •  臣服心动
    2021-02-15 16:58

    Another way to do this is to directly access the DBCollection object via the MongoTemplate:

    DBObject company = new BasicDBObject();
    ...
    DBCollection collection = mongoTemplate.getCollection("company");
    collection.insert(company);
    

提交回复
热议问题