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

Javascript for 'For' operator works incorrecly

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: JavaScript
    • Labels:
      None
    • Environment:
      db version v2.2.2, pdfile version 4.5; Windows 7
    • Windows
    • Hide

      I'm using the following script:

      colls = db.getCollectionNames();
      for (x in colls) {
      db.dump.insert(

      {x : colls[x]}

      ) ;
      };

      expected:
      >db.dump.find()

      { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "1" : "xxx" } { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "2" : "xxx1" } { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "3" : "xxx2" }

      ....

      { "_id" : ObjectId("511917a423ebdaf55649e5bb"), "12" : "system.indexes" }

      actual:
      >db.dump.find()

      { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "x" : "xxx" } { "_id" : ObjectId("511917a423ebdaf55649e5bb"), "x" : "system.indexes" }
      Show
      I'm using the following script: colls = db.getCollectionNames(); for (x in colls) { db.dump.insert( {x : colls[x]} ) ; }; expected: >db.dump.find() { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "1" : "xxx" } { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "2" : "xxx1" } { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "3" : "xxx2" } .... { "_id" : ObjectId("511917a423ebdaf55649e5bb"), "12" : "system.indexes" } actual: >db.dump.find() { "_id" : ObjectId("511917a423ebdaf55649e5ba"), "x" : "xxx" } { "_id" : ObjectId("511917a423ebdaf55649e5bb"), "x" : "system.indexes" }

      it seems that 'for' works not properly. I've tried 'for in' and usual 'for (x=0;x < 12; x++)' operations. Please see my steps to reproduce.

      PS: xxx, xxx1, xxx2 ... system.indexes are collections in my DB

      Thank you!

            Assignee:
            stephen.lee Stephen Lee
            Reporter:
            alexander.box Alexander Box
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: