1
比较同一文档中的多个值
我的问题是,如何找到发布的所有标题中包含艺术家姓名 这里只是一个例子,2个文件:MongoDB中
`{"release" : {"title" : "DEF day",
"artists" : {"artist" : {"role" : "1","name" : "DEF"}}}
}
{ "release" : {"title" : "XYZ day",
"artists" : {"artist" : {"role" : "1","name" : "KYC"}}}
}`
当我运行此以下查询:
`db.test.find({$where:
"this.release.title.indexOf(this.release.artists.artist.name) > -1"
})`
我得到的结果 “DEF日”,所以它做工精良! 但是一旦我运行此查询到我的原始数据(格式相同像上面)我得到这个:
`error: {
"$err" : "TypeError: Object 30 has no method 'indexOf'\n at _funcs1 (_funcs1:1:49) near 'his.release.artists.a' ",
"code" : 16722
}`
我的收藏是大(8GB +)。 只要看看上面的错误,任何人都可以告诉上述查询可能是什么问题?你的答案是赞赏。请。
你可以运行以下查询并发布其输出? find({field:{$ type:16}})' – bagrat
@ n9code 最初这个集合约20GB。我有一个300MB的小样本。 此外'发行'有更多的领域,除了标题,艺术家。 顺便说一句,在这里运行您的代码与300MB的示例是这样的结果: '这里是结果:在9646ms获取0条记录' – mrana
以下查询给我所有完全匹配(版本和艺术家)名称: db.releases.find({$其中: “this.release.title == this.release.artists.artist.name” }) 但我需要它包含了艺术家的名字称号。 – mrana