文档中的pages无法读取。 存储: var pageListSchema = new Schema({ _pid:String, name:String, eName:String, pages:[{name:String,id:String,type:String}] }); var pageList = db.model('pageList’,pageListSchema); var p = new pageList({_pid:getId,name:getName,eName:getEName,pages:[{name:"html",id:"0",type:"0"}]}); p.save(); 读取: pageList.find({pages:[{id:"0"}]},function(err,data){ console.log(data); }); pageList.find({pages:{$elemMatch:{id:"0"}}},function(err,data){ console.log(data); }); 尝试用了以上两种方法都无法取出,返回的是 [ { _pid: ‘510a3e793f30c5980f000001’ name: 'cc’, eName: 'cc’, _id: 510a3e803f30c5980f000002, __v: 0, pages: [ '[object Object]' ] } ] 这是为什么,请指教
2 回复
居然无法再编辑,把之前的代码高亮一下
var pageListSchema = new Schema({
pid:String,
name:String,
eName:String,
pages:[{name:String,id:String,type:String}]
});
var pageList = db.model('pageList',pageListSchema);
var p = new pageList({pid:getId,name:getName,eName:getEName,pages:[{name:"html",id:"0",type:"0"}]});
p.save();
读取:
pageList.find({pages:[{id:"0"}]},function(err,data){
console.log(data);
});
pageList.find({pages:{$elemMatch:{id:"0"}}},function(err,data){
console.log(data);
});
结果:
[ { _pid: '510a3e793f30c5980f000001'
name: 'cc',
eName: 'cc',
_id: 510a3e803f30c5980f000002,
__v: 0,
pages: [ '[object Object]' ] } ]