我想通过截止值过滤我的MongoDB集合。我的数据库设计如下:
{
"_id" : "178666a8393c643d3f29258616408879",
"sims" : {
"192ba2f580f69b53187a6c40c9225d0b" : 0.9912074804306030,
"d8a35b15f23bcd2d57e38406ace0fe3e" : 0.9840455055236816,
"d0f5018c07a694c35037cfae1f47021a" : 0.9687452912330627,
"61440ff39598ea8c14678da6f09e6c43" : 0.9722751975059509,
"d3e643b5b5e6abf2369da1aec12756cc" : 0.9448012113571167,
"c12e7f447958a496d989640a56575eeb" : 0.8973514437675476,
"5157fd7e3486a1c0fabccbee307e4e02" : 0.9997683167457581,
"ea5d4a218500f503daf7d69e39b7ad0f" : 0.9960342049598694,
},
"_id" : "ea5d4a218500f503daf7d69e39b7ad0f",
"sims" : {
"192ba2f580f69b53187a6c40c9225d0b" : 0.9979836344718933,
"d8a35b15f23bcd2d57e38406ace0fe3e" : 0.9958176016807556,
"d0f5018c07a694c35037cfae1f47021a" : 0.9867590069770813,
"61440ff39598ea8c14678da6f09e6c43" : 0.9884092211723328,
"d3e643b5b5e6abf2369da1aec12756cc" : 0.9697993993759155,
"c12e7f447958a496d989640a56575eeb" : 0.9323428869247437,
"5157fd7e3486a1c0fabccbee307e4e02" : 0.9973729848861694,
"ea5d4a218500f503daf7d69e39b7ad0f" : 1.0000001192092896,
}
}
现在,我想要一个新的数据库,所有项目都带有“sims”值,例如> 0.99。
我试过
db.getCollection('similarity_test').find({ "sims.value": { $gte: 0.99 } } )
和db.aggregate的类似尝试但我无法过滤所有“_id”和所有“sims”。 我被限制使用MongoDB 3.0,因此我无法应用$ filter功能。
编辑:
删除命名密钥后:
{
"_id" : "178666a8393c643d3f29258616408879",
"sims" : [
{
"sim" : 1.0000001192092896,
"key" : "178666a8393c643d3f29258616408879"
},
{
"sim" : 0.9960342049598694,
"key" : "ea5d4a218500f503daf7d69e39b7ad0f"
}],
"_id" : "ea5d4a218500f503daf7d69e39b7ad0f",
"sims" : [
{
"sim" : 0.9960342049598694,
"key" : "178666a8393c643d3f29258616408879"
},
{
"sim" : 1.0000001192092896,
"key" : "ea5d4a218500f503daf7d69e39b7ad0f"
},
{
"sim" : 0.9971756935119629,
"key" : "4160ee49e3e08ee237080c5b20dcfec7"
},
{
"sim" : 0.9877796173095703,
"key" : "f19ae8636304f8804f59c534a1fbc1d7"
}],
}