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

Inserting documents validates against `{_id: null}`

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.12.1
    • 2.10.0
    • Write Operations
    • None
    • 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;
          }

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: