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

delete operator in db.collection.find().forEach() sometimes behaves incorrectly

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.4, 2.4.8, 2.6.0-rc2
    • Component/s: JavaScript
    • Labels:
      None
    • ALL
    • Hide

      here is a somewhat minimal test case;

      N=100
      
      interpreterVersion() 
      
      // setup data
      db.coll.drop()
      for (i = 0; i < N; i++) {
          newItem = {"a":1,"b":2}; 
          db.coll.insert(newItem);
      }
      
      // update
      db.coll.find().forEach(function (obj) {
          obj.map = {
              "a":obj.a,
              "b":obj.b
              };
          delete obj.a;
          delete obj.b;
          db.coll.save(obj);
      });
      
      
      // check
      db.coll.aggregate( { $group :
                               { _id : "$map.a",
                                 totalA : { $sum : "$map.b" } 
                               }
                          });
      

      results:

       
      // when  N = 100
      // ok
      
      {
          "result" : [ 
              {
                  "_id" : 1,
                  "totalA" : 200
              }
          ],
          "ok" : 1
      }
      

      and fail

      // when N = 1000
      // error, should be no undefined
      {
      	"result" : [
      		{
      			"_id" : null,
      			"totalA" : 0
      		},
      		{
      			"_id" : 1,
      			"totalA" : 400
      		}
      	],
      	"ok" : 1
      }
      
      Show
      here is a somewhat minimal test case; N=100 interpreterVersion() // setup data db.coll.drop() for (i = 0; i < N; i++) { newItem = { "a" :1, "b" :2}; db.coll.insert(newItem); } // update db.coll.find().forEach(function (obj) { obj.map = { "a" :obj.a, "b" :obj.b }; delete obj.a; delete obj.b; db.coll.save(obj); }); // check db.coll.aggregate( { $group : { _id : "$map.a" , totalA : { $sum : "$map.b" } } }); results: // when N = 100 // ok { "result" : [ { "_id" : 1, "totalA" : 200 } ], "ok" : 1 } and fail // when N = 1000 // error, should be no undefined { "result" : [ { "_id" : null , "totalA" : 0 }, { "_id" : 1, "totalA" : 400 } ], "ok" : 1 }

      Hi,

      I'm using db.collection.find().forEach()
      to modify collection, rearranging fields inside,
      also using 'delete obj.property'.

      and depending on collection size, when it grows larger than
      some small threshold, (in my tests 1000),
      some fields of modified objects are set to undefiend as result, istead of actual numbers.

      i was able to reproduce it in both
      MongoDB version: 2.4.4, 2.4.8, 2.6.0-rc2

            Assignee:
            kamran.khan Kamran K.
            Reporter:
            bogdad Vladimir Shakhov
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: