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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.4, 2.4.8, 2.6.0-rc2
    • JavaScript
    • 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 }

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: