title: Read file with node.js, mongoose, gridfs-stream
body: <p>I am using mongoose and gridfs-stream to store and read files from mongodb. I am following the example here: <a href="https://github.com/aheckmann/gridfs-stream" rel="nofollow noreferrer">https://github.com/aheckmann/gridfs-stream</a></p>
  
  <p>Writing files into db is working fine but I faced a problem to read files.</p>
  
  <p>What the mongodb looks (show collections)</p>
  
  <pre><code>fs.chunks
  fs.files
  </code></pre>
  
  <p>What the file index looks (db.fs.files.find())</p>
  
  <pre><code>{ "_id" : ObjectId("5140392659851df70b000001"), 
  "filename" : "cover", 
  "contentType" : "binary/octet-stream", 
  "length" : 85734, 
  "chunkSize" : 262144, 
  "uploadDate" : ISODate("2013-03-13T08:30:30.299Z"), 
  "aliases" : null, 
  "metadata" : null, 
  "md5" : "4476b26067daa0677978ba501308a35d" }
  </code></pre>
  
  <p>Then I use this code to get file named "cover"</p>
  
  <pre><code>...
  var gfs = Grid(mongoose.connection.db, mongoose.mongo)
  var readstream = gfs.createReadStream('cover')
  </code></pre>
  
  <p>An error occured:</p>
  
  <pre><code>Error: cover does not exist
  at self.collection.self.fileId (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/gridfs/gridstore.js:198:26)
  at Cursor.nextObject (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:654:35)
  at Cursor.close (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:960:5)
  at Cursor.nextObject (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:654:17)
  at Cursor.nextObject.commandHandler (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:631:14)
  at Db._executeQueryCommand (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1702:5)
  at g (events.js:185:14)
  at EventEmitter.emit (events.js:115:20)
  at Server.Base._callHandler (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:130:25)
  at Server.connect.connectionPool.on.server._serverState (/mypath/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:517:20)
  </code></pre>
  
  <p>I googled it and found some possible related links:</p>
  
  <p><a href="https://github.com/mongodb/node-mongodb-native/issues/621" rel="nofollow noreferrer">https://github.com/mongodb/node-mongodb-native/issues/621</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13777974/why-gridfs-get-isnt-working-on-file-id-objectid-only-by-filename?rq=1">Why gridfs get isn&#39;t working on file id (ObjectId) only by filename</a></p>