Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB文本搜索查找长字符串,但不查找短字符串?_Mongodb - Fatal编程技术网

MongoDB文本搜索查找长字符串,但不查找短字符串?

MongoDB文本搜索查找长字符串,但不查找短字符串?,mongodb,Mongodb,在MongoDB3.6中,我有一个带有文本搜索索引的数据集合。它可以找到一个单词的较长版本,但不能找到较短的版本,如何使它同时找到两个版本 db.test.createIndex({name: 'text', description: 'text'}); db.test.insert({name: 'MYREALLYLONGNAME', description: 'MYREALLYLONGNAME'}); db.test.find({$text: {$search: 'MYREALLYLONG

在MongoDB3.6中,我有一个带有文本搜索索引的数据集合。它可以找到一个单词的较长版本,但不能找到较短的版本,如何使它同时找到两个版本

db.test.createIndex({name: 'text', description: 'text'});
db.test.insert({name: 'MYREALLYLONGNAME', description: 'MYREALLYLONGNAME'});

db.test.find({$text: {$search: 'MYREALLYLONGNA'}});
> FINDS IT

db.test.find({$text: {$search: 'MYREALLYL'}});
> DOES NOT FIND IT
这必须是:

db.test.find({{$text: {$search: /.*MYREALLYL.*/}})
db.test.find( { name: { $regex: /MYREALLYL/ } } )
注意:mongodb使用的正则表达式比 sql中的“LIKE”。使用正则表达式,您可以创建任何模式 那是你想象的

有关正则表达式的更多信息,请参阅此链接

确实如此,“部分文本搜索”是我应该搜索的