【发布时间】:2014-07-21 14:01:16
【问题描述】:
这真的让我发疯了。问题来了:
我在 Mongoose 中运行以下查询:
s.findSubdocument=function(uid, cb)
{
this.model('User').find({"flwng._id":uid.toString()}).select('flwng').exec(cb);
}
在以下用户架构上:
var userSchema= new mongoose.Schema(
{
uname:{type:String, index:{sparse:true, unique:true, dropDups:true}}, //the username
email:String,
pwd:{type:String},
flwng:[{_id : {type : mongoose.Schema.ObjectId},uname : String}], //_id of users I am following
flwrsz:Number,
flwngsz:Number,
feedsz:Number,
}, {j: 1});//j:1 means guarantee it is written to the journal.
userSchema.set('autoIndex', true);
userSchema.index({"fid":1}, {sparse:true, unique:true, dropDups:true});
userSchema.index({"flwng._id" : 1});
其中 uid="53c4f16c431247694f0000a3" ==> 但我得到一个空数组:(
当我在 mongo shell 中运行相同的查询时:
db.users.find({"flwng._id":"53c4f16c431247694f0000a3"});
我得到了正确的结果集。我尝试了在“flwng._id”上使用和不使用索引和模式,我试图删除索引,reIndex,我现在已经没有想法了。我对 Mongoose 做错了吗?
任何帮助将不胜感激 - 谢谢! 亨利
【问题讨论】: