marcello3d/node-mongolian — Issue #61: gridfs stream error
Author: mcfall2k2
Created: 2011-11-20 14:40:01+00:00
State: open

gridfs writeStream is raising the following error:

{ stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'Server Error: { errmsg: \'no such cmd\',\n \'bad cmd\': { getLastError: 1 },\n ok: 0 }',
result:
{ errmsg: 'no such cmd',
'bad cmd': { getLastError: 1 },
ok: 0 } }

The file has been written to mongo (verified that it is correct in the stream error event) and appears to be complete. Obviously the 'close' event on the stream is not being emited. I have verified that the trainer example is also throwing the same error.

Versions:
node 0.4.11

├── mongodb@0.9.7-0
├── mongolian@0.1.13
├── taxman@0.1.1
├── test@0.4.3
└── waiter@0.1.1

test code:

var Db= require('mongodb').Db,
Server= require('mongodb').Server,
Mongolian = require('mongolian'),
fs = require('fs');

var server = new Mongolian()
var db = server.db('mongolian_test')

////// Grid FS

var gridfs = db.gridfs()

// Create new file write stream
var stream = gridfs.create({
filename:"test.jpg",
contentType: "text/plain"
}).writeStream()

// Pipe license file to gridfile
fs.createReadStream(__dirname+'/data/test.jpg').pipe(stream)

// Read file back from gridfs
stream.on('close', function() {
gridfs.findOne("test.jpg", function (err, file) {
if (err) throw err
console.log("opened file:",file)
var read = file.readStream()
read.on('data', function (chunk) {
console.log("chunk["+chunk.length+"] = <"+chunk+">")
})
read.on('end', function() {
console.log("all done")
})
})
})

stream.on('error', function(err){
console.log('stream:error:', err)
gridfs.findOne("test.jpg", function (err, file) {
if (err) throw err
console.log("opened file:",file)
var read = file.readStream()
read.on('data', function (chunk) {
console.log("chunk["+chunk.length+"] = <"+">")
})
read.on('end', function() {
console.log("all done")
})
})
})