【发布时间】:2019-03-18 15:39:10
【问题描述】:
我是 MongoDB 新手,正在尝试比较 MongoDB 集合中的 2 个字段。
字段是属性(对象)和集合(数组)
{
"_id" : ObjectId("55ae1e47309ffcbd1b67bd6c"),
"collections" : [
{
"collection_code" : "9TEST",
"_id" : ObjectId("5c76eee4bb4afe3a3603eeb3")
}
],
"attributes" : {
"collection_code" : "9TEST"
}
}
我的查询是
db.companies.find({ $where : "this.attributes.collection_code == this.collections[collection_code]" })
遇到错误
{
"message" : "TypeError: Cannot read property 'collection_code' of undefined" +
"at _funcs1 (_funcs1:1:45) near 'on_code == this.collections[collection_co' ",
"$err" : "TypeError: Cannot read property 'collection_code' of undefined" +
"at _funcs1 (_funcs1:1:45) near 'on_code == this.collections[collection_co' ",
"code" : 16722,
"name" : "MongoError"
}
非常感谢任何帮助。提前致谢。
【问题讨论】:
标签: mongodb mongodb-query