Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js nodejs mongodb Gridstore.exist无限循环_Node.js_Mongodb_Mongoose_Gridfs_Node Mongodb Native - Fatal编程技术网

Node.js nodejs mongodb Gridstore.exist无限循环

Node.js nodejs mongodb Gridstore.exist无限循环,node.js,mongodb,mongoose,gridfs,node-mongodb-native,Node.js,Mongodb,Mongoose,Gridfs,Node Mongodb Native,我正在尝试使用mongodb的GridStore,当我尝试以下代码GridStore.exist(db,req.params.filename,function(err,result){ 下面是整个代码及其调试输出 var express = require('express'), mongoose = require('mongoose'); var app = express(); var db = mongoose.createConnection('mongodb://loc

我正在尝试使用mongodb的GridStore,当我尝试以下代码
GridStore.exist(db,req.params.filename,function(err,result){

下面是整个代码及其调试输出

var express = require('express'),
    mongoose = require('mongoose');

var app = express();

var db = mongoose.createConnection('mongodb://localhost/dev_gridfs');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.errorHandler({dumpExceptions: true, showStack : true}));

app.get('/', function(req,res){
    console.log('main');
    res.send('<img src="/images/test.jpg"/>');
});

var GridStore = mongoose.mongo.GridStore;

app.get('/images/:filename', function(req, res){
    console.log('in get image: ' + req.params.filename);
    GridStore.exist(db, req.params.filename, function(err, result){
        console.log('in gridstore exist');
        if (err) {
            console.log(err);
            res.status(500);
            res.send();
        }
        if (result) { 
            console.log('file found');
            //TODO code for sending the file
            res.send('');
        } else {
            res.status(404);
            res.send();
        }
    });
});


app.listen(3000);
console.log('listening on 3000');
版本:[节点:v0.8.11,快车:3.0.0rc4,猫鼬:3.2.1]


非常感谢您的建议。我不确定这是否是节点mongodb驱动程序的错误,我还没有在驱动程序问题跟踪程序中发现这是一个问题。

我犯了一个错误!GridStore需要mongodb对象,而不是Mongoose DB对象。进行了以下代码更改,其他一切都按预期工作

更改了上面代码中显示的以下行

var db = mongoose.createConnection('mongodb://localhost/dev_gridfs');
作为


听起来它可能在等待
db
打开连接。你确定打开正常吗?
db
似乎正常!我已经保存了。下面是代码
var FileSchema=new mongoose.Schema({name:String});var File=db.model('File',FileSchema);app.get('/images/:filename',function(req,res){console.log('in get image:'+req.params.filename);var f=新文件({name:req.params.filename});f.save(函数(err){if(!err)console.log('filename saved');});
var db = mongoose.createConnection('mongodb://localhost/dev_gridfs');
var mongooseDb = mongoose.createConnection('mongodb://localhost/dev_gridfs');
var db = mongooseDb.db;