mongoDb:Cannot 查找索引以验证连接字段是否唯一

mongoDb:Cannot find index to verify that join fields will be unique

嘿,我需要合并我的两个 collections,位 mongo 返回 "Cannot find index to verify that join fields will be unique"

1.create 唯一索引 2.removewhenMatched/whenNotMatched

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 聚合阶段需要 unique index on the identifier fields

$merge requires a unique, index with keys that correspond to the on identifier fields. Although the order of the index key specification does not matter, the unique index must only contain the on fields as its keys.

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

确保您的唯一索引 ID 是类型:ObjectID。