[JAVA-2946] I have Question regarding saving java object in mongoDB and getting mongo Id back Created: 28/Aug/18  Updated: 11/Sep/19  Resolved: 29/Aug/18

Status: Closed
Project: Java Driver
Component/s: API, BSON, Codecs
Affects Version/s: 3.6.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Aniket M Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

i am using java 1.8 and mongo java Driver version 3.6


Issue Links:
Duplicate
duplicates JAVA-2674 POJO ID property is not populated aft... Closed

 Description   

Hi Team , 

I saving my java object to mongo DB using proper codec and able to save object in mongo

i am using collection.insertOne(javaObject);

i have @BsonId ObjectId id in my class . when i save object to database i don't see database generated id reflecting in  ObjectId id (i see this is as null , even after saving object to DB) field of my class .

to get this DB generated Id so i have to query mongo Db one more time or there is some other way to do so ?

Could you please help with above .

 

Thanks..!

Aniket

 



 Comments   
Comment by Ross Lawley [ 29/Aug/18 ]

Hi aniket20365@gmail.com,

I'm marking this ticket as a duplicate of JAVA-2674. In short you will need to generate the _id for the object that you are saving. Please watch that ticket for future updates.

Ross

Generated at Thu Feb 08 08:58:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.