簡體   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