[JAVA-1167] Inserting documents validates against `{_id: null}` Created: 14/Apr/14  Updated: 02/Apr/16  Resolved: 13/Jun/14

Status: Closed
Project: Java Driver
Component/s: Write Operations
Affects Version/s: 2.10.0
Fix Version/s: 2.12.1

Type: Bug Priority: Major - P3
Reporter: Daniel Gottlieb (Inactive) Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on JAVA-467 Calling setReadPreference(ReadPrefere... Closed
Backwards Compatibility: Minor Change

 Description   

The java driver, by virtue of doing a null check on the `get("_id")` instead of a `containsField("_id")`, will try to set the `_id` to a new `ObjectId`. Not sure about all of the other drivers, but the javascript driver allows `null`. With respect to the use case of trying to replicate an existing collection, this causes a problem.

In DBCollection.java:

    public Object apply( DBObject jo , boolean ensureID ){
 
        Object id = jo.get( "_id" );
        if ( ensureID && id == null ){
            id = ObjectId.get();
            jo.put( "_id" , id );
        }
 
        doapply( jo );
 
        return id;
    }



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by Githook User [ 01/Aug/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1167: Backing out this change after deciding that it's too risky, as users may be relying on the current behaviour.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/201ae41371bd1c4815af6451d05fa7a2691107ad

Comment by Githook User [ 01/Aug/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1167: Changed save and insert such that they check for the existence of the _id key rather than comparing it to null. This lets you insert a document with _id of null (of course, you can't do that more than once per collection).
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/af9017b27f64245702fd996c9bea1491c4f458dd

Comment by Jeffrey Yemin [ 01/May/14 ]

I think the way we're going to have to approach this so as not to break existing clients is to allow control over _id generation. So linking to JAVA-467.

Comment by Githook User [ 28/Apr/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1167: Backing out this change after deciding that it's too risky, as users may be relying on the current behaviour.
Branch: 2.12.x
https://github.com/mongodb/mongo-java-driver/commit/201ae41371bd1c4815af6451d05fa7a2691107ad

Comment by Jeffrey Yemin [ 28/Apr/14 ]

Backing this change out as too risky for a patch release.

Comment by Githook User [ 25/Apr/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1167: Changed save and insert such that they check for the existence of the _id key rather than comparing it to null. This lets you insert a document with _id of null (of course, you can't do that more than once per collection).
Branch: 2.12.x
https://github.com/mongodb/mongo-java-driver/commit/af9017b27f64245702fd996c9bea1491c4f458dd

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