Spring mongodb get ID of inserted item after Save
问题 I am working with Spring MongoDb. I create various entities using insert method: http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoOperations.html#insert-java.lang.Object- However, all methods return void . I need to return the ObjectId of the inserted document. What is the best way to get it? 回答1: This is pretty interesting and thought I would share. I just figured out the solution for this with the help of BatScream comment above: You