-
Type: Task
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: 2.2.30
-
Component/s: None
-
None
-
Environment:node v7.4.0
mongo node driver 2.2.30
-
Empty show more show less
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(); }); }); }); });