节省:
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]' ] } ]
有两种读取数据的方法,但是为什么我得到的是字符串而不是对象