[JAVA-2114] Better error message for "Invalid BSON field name" Created: 11/Feb/16 Updated: 26/Jul/22 Resolved: 26/Jul/22 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Error Handling |
| Affects Version/s: | 3.2.0 |
| Fix Version/s: | 4.8.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Aleksey Korolev | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 4 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I'm getting java.lang.IllegalArgumentException: "Invalid BSON field name" for update operation. |
| Comments |
| Comment by Githook User [ 26/Jul/22 ] |
|
Author: {'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}Message: Improve error message for invalid field names (#985) For replacement documents, it's now:
|
| Comment by Jeffrey Yemin [ 27/Mar/19 ] |
|
There is an undeprecated variant of replaceOne: replaceOne(Bson filter, TDocument replacement, ReplaceOptions replaceOptions) |
| Comment by Peter Williamson [ 27/Mar/19 ] |
|
Using replaceOne is a viable alternative if you want to replace the whole document, but it's marked as deprecated in the 3.7 driver. So this bug should be fixed or replaceOne reinstated. |
| Comment by Peter Williamson [ 27/Mar/19 ] |
|
IMHO this is incorrect validation. In the mongo client you can update without needing $set, db.collection.update( { _id: key}, { _id: key, field: value } ) works fine, but fails in the java driver with the "Invalid BSON field name _id" exception. The same error occurs with upsert=true and having to use $set with an upsert makes no sense. |
| Comment by Michael J Winters [ 04/Mar/18 ] |
|
here's a PR https://github.com/mongodb/mongo-java-driver/pull/460. |
| Comment by Naga Mayakuntla [ 16/Aug/17 ] |
|
Any update on this? |
| Comment by Jeffrey Yemin [ 11/Feb/16 ] |
|
OK, I see now. Thanks for reporting this. We'll see what we can do in a future release to address this. |
| Comment by Aleksey Korolev [ 11/Feb/16 ] |
|
Sorry for not giving enough detail. |
| Comment by Jeffrey Yemin [ 11/Feb/16 ] |
|
Looks like the message is generated from here, which does include the field name. Can you provide the full stack trace? |