Mongo Db search by indexed field

前端 未结 2 540
别跟我提以往
别跟我提以往 2021-01-14 15:38

I add field \'search_string\' to my document and index it. db.my_collection.createIndex({search_string: \"text\"}) Search_string contains this: \'a ar are aren

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 16:22

    By default, MongoDB uses English for text index and the stop words are not indexed.

    If you specify a language value of "none", then the text search uses simple tokenization with no list of stop words and no stemming.

    So you should create your index like this :

    db.my_collection.createIndex( { search_string : "text" }, { default_language: "none" } )

    MongoDB documentation here.

提交回复
热议问题