[JAVA-3392] Custom Key with nested objects fail to find by key. Created: 21/Aug/19 Updated: 27/Oct/23 Resolved: 26/Aug/19 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 3.8.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Attila Grof | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Java 8, MongoDB 4.0.6 Enterprise |
||
| Description |
|
I am having problems using custom keys with nested objects. If I insert a record successfully I cannot find it by its key. If I try to use the ReplaceOneModel with upsert=true, then I get BulkWriteException : rite errors: [BulkWriteError{index=0, code=66, message='After applying the update, the (immutable) field '_id' was found to have been altered to _id:....... If i remove the nested object everything works fine tough..... This simple test fails with a complex key:
|
| Comments |
| Comment by Attila Grof [ 27/Aug/19 ] | ||||||||||||||||||||||||||||||
|
From a usage point of view this is very strange. Lets say two different systems use the same collection, how are they suppose to know the other system's json generation attribute ordering logic. The Java driver automatically ordered the filter into alphabetical order when used with pojos ( I do not have control over that class). Shouldn't it be the mongo server's responsibility to order filter and insert attributes in the same order ?
Returns the previously inserted element
Returns NULL
From a developer point of view these two queries should return the same data. | ||||||||||||||||||||||||||||||
| Comment by Esha Bhargava [ 26/Aug/19 ] | ||||||||||||||||||||||||||||||
|
9freedy9@gmail.com You are correct that filtering by the value of a document requires that the field order matches. So this would not be considered a bug. Consider using $elemMatch when you want to match against a document. | ||||||||||||||||||||||||||||||
| Comment by Attila Grof [ 22/Aug/19 ] | ||||||||||||||||||||||||||||||
|
So I figured out that the filter is ordering properties in alphabetical order and the data properties need to be saved in the same order. | ||||||||||||||||||||||||||||||
| Comment by Attila Grof [ 22/Aug/19 ] | ||||||||||||||||||||||||||||||
|
As it turns out with nested objects in key, the filter json need to have the same order as the data json. Is this a feature or bug? |