Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1167

Inserting documents validates against `{_id: null}`

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.12.1
    • Affects Version/s: 2.10.0
    • Component/s: Write Operations
    • Labels:
      None
    • Minor Change

      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;
          }
      

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            daniel.gottlieb@mongodb.com Daniel Gottlieb (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: