当部分字符串字段相同时,Mongodb文本索引重复键错误 [英] Mongodb text index Duplicate Key Error when part of string field same

查看:105
本文介绍了当部分字符串字段相同时,Mongodb文本索引重复键错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

{
'name':'apple'
}



doc2:

doc2:

{
'name':'apple juice'
}

当我使用pymongo创建文本索引时:

when I create text index with pymongo:

db.products_collection.create_index([('name', TEXT)],
                                     unique=True,
                                    background=True)

它给我一个错误:


E11000重复键错误收集:c.items_collection索引:
name_text_alias_text dup键:{: apple,:10.5 }

E11000 duplicate key error collection: c.items_collection index: name_text_alias_text dup key: { : "apple", : 10.5 }

有人知道为什么吗?我不能为文本字符串添加 unique = True 吗?

Some one know why? I cannot add unique=True for text string?

推荐答案

文本index将字符串拆分为标记(单词),这些标记构成键。因此,在您的示例中, apple是重复键。

A text index splits strings into tokens (words), and those tokens form the keys. So in your example, "apple" is a duplicates key.

通常,唯一的文本索引是个坏主意。

Generally, unique text index is the bad idea.

这篇关于当部分字符串字段相同时,Mongodb文本索引重复键错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆