Inserting documents validates against `{_id: null}`

XMLWordPrintableJSON

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

      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:
              Jeffrey Yemin
              Reporter:
              Daniel Gottlieb (Inactive)
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: