2013-10-27 82 views
0

我正在運行NodeJS/w ExpressJS和MongoDB。我正在嘗試創建一個非常簡單的API,但某些功能無法正常工作。當我運行api.js並去/api/media/movies它給我這個輸出,而不是數據庫結果。我知道數據庫中有結果,任何人都可以告訴我我做錯了什麼?在Express中沒有得到MongoDB的預期結果

{ 
    options: { }, 
    _conditions: { 
    type: "Movie" 
    }, 
    _updateArg: { }, 
    op: "find" 
} 

api.js

var app, express, models; 

express = require('express'); 

models = require('./Librarian/models'); 

app = express(); 

app.get('/api/media/movies', function(req, res) { 
    var movies; 
    movies = models.Media.find({ 
    type: "Movie" 
    }); 
    res.json(movies); 
}); 

app.listen(3000); 

./Librarian/models.js

var Media, config, mongoose; 

mongoose = require('mongoose'); 

config = require('../config'); 

mongoose.connect(config.mongo.connectString); 

Media = mongoose.model('Media', { 
    type: { 
    type: String 
    }, 
    path: { 
    type: String, 
    unique: true 
    } 
}); 

module.exports = { 
    Media: Media 
}; 

回答

0

忘了我在異步ENV我工作。此作品:

var app, express, models; 

express = require('express'); 

models = require('./Librarian/models'); 

app = express(); 

app.get('/api/media/movies', function(req, res) { 
    models.Media.find({ 
    type: "Movie" 
    }, function(err, movies) { 
    res.json(movies); 
    }); 
}); 

app.listen(3000); 
相關問題