Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-23936

insertOne method accepts non-documents

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.14
    • Affects Version/s: 3.3.5
    • Component/s: Shell
    • None
    • Fully Compatible
    • ALL
    • Hide
      >  db.foo.drop()
      >  db.foo.insertOne(1)
      {
      	"acknowledged" : true,
      	"insertedId" : ObjectId("571fa2fa9e984050a87fc904")
      }
      > db.foo.findOne()
      {
      	"_id" : ObjectId("571fa2fa9e984050a87fc904"),
      	"toPercentStr" : function () {
          return (this * 100).toFixed(2) + "%";
      },
      	"zeroPad" : function (width) {
          return ('' + this).pad(width, false, '0');
      }
      }
      
      Show
      > db.foo.drop() > db.foo.insertOne(1) { "acknowledged" : true, "insertedId" : ObjectId("571fa2fa9e984050a87fc904") } > db.foo.findOne() { "_id" : ObjectId("571fa2fa9e984050a87fc904"), "toPercentStr" : function () { return (this * 100).toFixed(2) + "%"; }, "zeroPad" : function (width) { return ('' + this).pad(width, false, '0'); } }
    • Platforms 2016-09-19

      The insertOne method accepts non-documents and ends up inserting garbage data. The insert method reports an error in the same situation.

      > db.foo.insert(1)
      2016-04-26T13:22:39.696-0400 E QUERY    [thread1] Error: attempted to save a number value.  document expected. 
      

            Assignee:
            matt.cotter Matt Cotter
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: