如何使MongoDB文本搜索找到部分匹配

时间:2017-11-09 02:32:30

标签: mongodb

此代码末尾的find()找不到插入的文档。

注意:我使用的是MongoDB版本3.2.15。

  1. 为什么不呢?
  2. 如何更改索引或搜索参数以便找到它?
  3.   
    
            db['test'].createIndex(
              {
                name: 'text',
                email: 'text',
                phoneNumber: 'text'
              },
              {
                default_language: 'none',
                name: 'text_index',
                $caseSensitive: false,
                $diacriticSensitive: false,
              } );
    
            db['test'].insert({
              name: 'Chaney Waste Management',
              email: 'cliffchaney@gmail.com',
              phoneNumber: '(402)555-1212'
            });
    
            db['test'].find( {
                $text:
                  {
                    $search: 'manage',
                    $language: 'none',
                    $caseSensitive: false,
                    $diacriticSensitive: false
                  }
              } );  // Finds nothing! Why?
          
    
    

    如果重要,这是db.hostInfo()调用的完整结果:

    {
        "system" : {
            "currentTime" : ISODate("2017-11-09T02:38:45.379Z"),
            "hostname" : "Cliff-Surface:3001",
            "cpuAddrSize" : 64,
            "memSizeMB" : 16310,
            "numCores" : 4,
            "cpuArch" : "x86_64",
            "numaEnabled" : false
        },
        "os" : {
            "type" : "Windows",
            "name" : "Microsoft Windows 8",
            "version" : "6.2 (build 9200)"
        },
        "extra" : {
            "pageSize" : NumberLong(4096)
        },
        "ok" : 1.0
    }
    

0 个答案:

没有答案