gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:52:35 24 4
gpt4 key购买 nike

嘿,我需要合并我的两个集合,但是 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"
}}
])

预期:retuns GeoLite2-City-Blocks-IPv4 include 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 集合中存在一个唯一索引。

关于mongoDb:找不到索引来验证连接字段是否唯一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57881817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com