Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-246

Cursors are inefficiently constructed and consequently cannot be promisified.

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.9
    • Affects Version/s: 1.4.8
    • Component/s: None
    • 1

      This issue is in reference to lib/mongodb/scope.js

      There is a constructor function, Cursor, which defines methods every time the constructor is called. These methods should be moved to the prototype and the _scope_options and _cursor variables should be moved to instance variables.

      A lot of the defined methods just call-through to the _cursor object which makes me believe Cursor should inherit from Cursor2. It looks like somebody else had this idea as well as I can see require('util').inherits at the top of the file but it is never used anywhere.

      Fixing the inheritance chain would also make it possible to promisify the Cursor. For example, promisifying the Cursor constructor with bluebird right now doesn't do anything because Cursors returned by the API use this internal Cursor function which is not exposed anywhere.

      It also appears that, on line 93, _fields is leaked to the global scope.

      I am willing to do the work to fix these issues if nobody else is working on it. I would like to fix it quickly.

      Just for reference, other people are also running in to issues: http://stackoverflow.com/questions/23771853/how-can-i-promisify-the-mongodb-native-javascript-driver-using-bluebird

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            KenPowers Kenneth Powers [X]
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: