繁体   English   中英

如何在mongotemplate.save操作执行期间获取mongodb集合中文档的对象ID?

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

使用 MongoTemplate,我在集合中保存了一个 json。 我想 objectid 是由 MongoDB 自动生成的。

如何在保存时立即获取objectid?

mongotemplate.save(data,"collection");

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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