数据库里明明有东西啊,log出来的为何是空的数组 []
数据库中有东西的
mongo 127.0.0.1:27017 MongoDB shell version: 2.6.1 connecting to: 127.0.0.1:27017/test
show collections pic system.indexes db.pic.find() { “_id” : ObjectId(“55532b9e2817911cc4a15cee”), “url” : “http://img0.bdstatic.com/img/image/shouye/touxiangwise01.jpg” }
搜不出东西
var db=require(“mongoose”);
db.connect(‘mongodb://localhost/pic’);
var pic_schema = new db.Schema({ url: String });
pic_schema.methods.findPic = function(cb) { return this.model(‘MPicture’).find( cb); }
var MPicture=db.model('MPicture’, pic_schema);
MPicture.find({},function(err,pics) { console.info(‘result found’); });
var pic = new MPicture({});
pic.findPic(function(err, result) { console.log(err); console.log(result); });
结果
result found null []
这是怎么了?