mongodb中创建全文索引

每个mongodb中只能创建一个全文索引,其他的索引需要输入整个字段,才能够查询出来。

1.创建索引:db.structs.news.ensureIndex({content:"text",publish_time:"text",title:"text"})

2索引的使用:db.structs.news.find( { $text: { $search:  "from" } } )

全文索引参考网站:https://www.jianshu.com/p/f30a8088b73f

全文索引:
全文检索要用到”$text“判断符,而想要进行数据的查询则使用”$search“运算符:
查询指定关键字:{‘$search’:’查询关键字’}
查询多个关键字,或关系:{‘$search’:’查询关键字 查询关键字 …’}
查询多个关键字,与关系:{‘$search’:’’查询关键字’ ’查询关键字’ …’}
查询多个关键字,排除某一个:{‘$search’:’查询多个关键字 查询多个关键字 …’}
原文地址:https://www.cnblogs.com/lxz123/p/12889369.html