嘿,我需要合并我的两个集合,但 mongo 返回“无法找到索引来验证连接字段是否唯一”
1.创建唯一索引 2.删除whenMatched/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"
}}
])
Run Code Online (Sandbox Code Playgroud)
预期:返回 GeoLite2-City-Blocks-IPv4 包括 GeoLite2-City-Locations-ja