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

Warnings pointing to Node Driver

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.0.0
    • Affects Version/s: 2.2.30
    • Component/s: None
    • Labels:
      None
    • Environment:
      node v7.4.0
      mongo node driver 2.2.30

      Sample code from tutorial returns a deprecation warning.

      (node:89372) DeprecationWarning: Calling an asynchronous function without callback is deprecated.
      

      In node_modules/mongodb/lib/gridfs/grid_store.js in line 452, we are calling close() without a callback. When `fs.close(file);` is changed to `fs.close(file,function(){});` the warning dissapears.

      // read.js
      
      var Db = require('mongodb').Db,
      MongoClient = require('mongodb').MongoClient,
      Server = require('mongodb').Server,
      ReplSetServers = require('mongodb').ReplSetServers,
      ObjectID = require('mongodb').ObjectID,
      Binary = require('mongodb').Binary,
      GridStore = require('mongodb').GridStore,
      Grid = require('mongodb').Grid,
      Code = require('mongodb').Code,
      fs = require('fs'),
      assert = require('assert');
      
      var db = new Db('test', new Server('localhost', 27017));
      // Establish connection to db
      db.open(function(err, db) {
      // Our file ID
      var fileId = new ObjectID();
      
      // Open a new file
      var gridStore = new GridStore(db, fileId, 'w');
      
      // Read the filesize of file on disk (provide your own)
      var fileSize = fs.statSync('./surfer.png').size;
      // Read the buffered data for comparision reasons
      var data = fs.readFileSync('./surfer.png');
      
      // Open the new file
      gridStore.open(function(err, gridStore) {
      
      // Write the file to gridFS
      gridStore.writeFile('./surfer.png', function(err, doc) {
      
        // Read back all the written content and verify the correctness
        GridStore.read(db, fileId, function(err, fileData) {
          assert.equal(data.toString('base64'), fileData.toString('base64'))
          assert.equal(fileSize, fileData.length);
      
          db.close();
        });
      });
      });
      });
      

            Assignee:
            jessica.lord Jessica Lord
            Reporter:
            jorge.imperial@mongodb.com Jorge Imperial-Sosa (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: