简体   繁体   中英

How to get the object id of the document in a mongodb collection during mongotemplate.save operation is executed?

Using MongoTemplate, I have saved a json in a collection. The objectid is generated automatically by MongoDB, I suppose.

How to get the objectid at the instant while saving?

mongotemplate.save(data,"collection");

如果我理解你正确你可以这样做,如果对象“数据”有字段“id”

mongotemplate.save(data,"collection").getId();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM