[JAVA-3811] id is being replaced by _id, of the inner object, when updating data of MongoDB using Java Driver Created: 11/Aug/20 Updated: 13/Aug/20 Resolved: 13/Aug/20 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Akash Shrestha | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I'm trying to update an object of MongoDB. I'm using Java Driver (Sync). After a 'create' operation, the data is persisted as follows:
Now, I want to modify the 'id' parameter of the images array. So I update the data using getCollection().updateOne(filterCondition, combine(updateData)), but it is persisted as below:
As you can see in the updated data, the 'id' property of the images array is now '_id' after update operation. I had provided the JSON with 'id' field but somehow the Mongo Client considered 'id' as '_id' and persisted '_id'. This happens when replaceOne() is used too. This doesn't happen with the create operation as you can see above. Is this an expected behavior when update operation is done? Why is MongoDB treating 'id' and '_id' as same? |
| Comments |
| Comment by Jeffrey Yemin [ 13/Aug/20 ] |
|
shrestha.akash01@gmail.com looks like you found your answer so I'm closing this issue. |
| Comment by Akash Shrestha [ 12/Aug/20 ] |
|
Found the answer here: JAVA-2750 |