1
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]' ] } ]
有讀數據的兩個方法,但爲什麼我得到了一個字符串而不是對象
你能澄清這個問題嗎?如果你使用console.log(data [0] .pages [0]),那麼返回結果是什麼? – Ross