mongoDb:找不到索引来验证连接字段是否唯一



嘿,我需要合并我的两个集合,但是mongo重新调整"找不到索引来验证连接字段是否是唯一的">

1.创建唯一索引 2.删除何时匹配/何时不匹配

db.getCollection("GeoLite2-City-Blocks-IPv4").aggregate([
{$match:{longitude:{$gt:175,$lt:180}}},
{$merge:{
into:"GeoLite2-City-Locations-ja",
on:"geoname_id",
whenMatched: "replace",
whenNotMatched: "insert" 
}}
])

预期:重新调整GeoLite2-City-Blocks-IPv4包括GeoLite2-City-Locations-ja

$merge聚合阶段需要标识符字段的唯一索引:

$merge需要一个唯一的索引,其键对应于 标识符字段。虽然索引键规范的顺序 没关系,唯一索引必须只包含 on 字段作为 它的钥匙。

对于您的操作,需要GeoLite2-City-Locations-ja集合上存在一个唯一索引,该集合包含字段geoname_id

确保唯一索引 ID 为类型:对象 ID。

最新更新