我已经看过这些帖子:
但是我的问题不同。当我运行这个查询时:
db.usercollection.find({$where: "this.profile.name.length < 20"}).limit(2);
我得到了以下错误:
Error: error: {
"ok" : 0,
"errmsg" : "TypeError: this.profile is undefined :\n_funcs2@:1:24\n",
"code" : 139
}
当我运行这个查询时:
db.usercollection.find({"profile.name": {$exists: true}, $where: "this.profile.name.length <20"}).limit(2);
没有错误,但是结果为空,尽管我的集合中有两个文档的profile.name<20
MongoDB shell版本:3.2.11
this.profile is undefined
,为什么不尝试检查字段呢?例如:db.usercollection.find({"profile": {"$exists": true}, "$where": "this.profile.name.length <20"}).limit(2);
。 - chridam