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

Sharded findAndModify will not implicitly create the database if it does not exist

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.5, 3.5.7
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Fully Compatible
    • ALL
    • v3.4
    • Hide

      Start a ShardingTest and run:

      t = db.find_and_modify4;
      t.drop();
      
      // this is the best way to build auto-increment
      function getNextVal(counterName) {
          var ret = t.findAndModify({
              query: {_id: counterName},
              update: {$inc: {val: 1}},
              upsert: true, 'new': true,
          });
          return ret;
      }
      
      assert.eq(getNextVal("a"), {_id: "a", val: 1});
      
      Show
      Start a ShardingTest and run: t = db.find_and_modify4; t.drop(); // this is the best way to build auto-increment function getNextVal(counterName) { var ret = t.findAndModify({ query: {_id: counterName}, update: {$inc: {val: 1}}, upsert: true , ' new ' : true , }); return ret; } assert .eq(getNextVal( "a" ), {_id: "a" , val: 1});
    • Sharding 2017-05-29

      The sharded findAndModify will fail with NamespaceNotFound error if the database does not exist. The problem was introduced by this change.

            Assignee:
            kaloian.manassiev@mongodb.com Kaloian Manassiev
            Reporter:
            misha.tyulenev@mongodb.com Misha Tyulenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: