2022.12.31周总结
mongodb全文检索
1.
mongod --setParameter textSearchEnabled=true开启检索命令
2.考虑以下 posts 集合的文档数据,包含了文章内容(post_text)及标签(tags):
{
"post_text": "enjoy the mongodb articles on Runoob",
"tags": [
"mongodb",
"runoob"
]
}
3.现在我们已经对 post_text 建立了全文索引,我们可以搜索文章中的关键词 runoob:
>db.posts.find({$text:{$search:"runoob"}})
以下命令返回了如下包含 runoob 关键词的文档数据:
{
"_id" : ObjectId("53493d14d852429c10000002"),
"post_text" : "enjoy the mongodb articles on Runoob",
"tags" : [ "mongodb", "runoob" ]
}

浙公网安备 33010602011771号