admin管理员组文章数量:1402801
Here's the relevant code:
app.get('/all', function(req,res) {
Party.find({},[],function(p) {
console.log(p);
});
res.redirect('/');
});
should return all collections from the database - returns null in the console.
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/impromptu');
var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
general stuff about initialization
var PartySchema = new Schema({
what : String,
when : String,
where : String
});
mongoose.model('Party',PartySchema);
// Models
var Party = db.model('Party');
schema
I have everything else for it setup properly, I can save collections just fine, can't retrieve all for some reason...
Checked /var/log/mongodb.log and it is indeed connecting.
Any ideas?
Here's the relevant code:
app.get('/all', function(req,res) {
Party.find({},[],function(p) {
console.log(p);
});
res.redirect('/');
});
should return all collections from the database - returns null in the console.
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/impromptu');
var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
general stuff about initialization
var PartySchema = new Schema({
what : String,
when : String,
where : String
});
mongoose.model('Party',PartySchema);
// Models
var Party = db.model('Party');
schema
I have everything else for it setup properly, I can save collections just fine, can't retrieve all for some reason...
Checked /var/log/mongodb.log and it is indeed connecting.
Any ideas?
Share Improve this question edited Apr 16, 2011 at 1:32 MPelletier 16.7k18 gold badges89 silver badges140 bronze badges asked Mar 1, 2011 at 1:58 acrognaleacrognale 3001 gold badge3 silver badges8 bronze badges1 Answer
Reset to default 9Assuming you're using mongoose after v1.0 that null is the err argument to your callback (there are two ... first the error then the results) ... Try this:
Party.find({},[],function(err,p) {
console.log(p);
});
本文标签: javascriptModelfind() returning null json object in mongoose (mongodb) on nodeStack Overflow
版权声明:本文标题:javascript - Model.find() returning null json object in mongoose (mongodb) on node - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744119248a2591658.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论