如何从 mongoDB 的标题中找到关键字?
从包含一个或多个单词的标题中查找关键字。
// data
{
title: "hello my name is joy", section_name: "talk", category_path: "info"
}
//From Keyword collection
[
{keyword: "hello", section_name: "talk", category_path: "info", username: ["joy", "sadness"]},
{keyword: "hello joy", section_name: "talk", category_path: "info", username: ["joy"]},
{keyword: "shoes", section_name: "market", category_path: "sell", username: ["joy"]}
]
这是我想去获取数据。
// the Result
[
{keyword: "hello", section_name: "talk", category_path: "info", username: ["joy", "sadness"]},
{keyword: "name joy", section_name: "talk", category_path: "info", username: ["joy"]}
]
我试过这段代码
// No Data
db.getCollection('keyword').find({"keyword": {$regex: "hello my name is joy"}, "section_name":"talk", "category_path": "info"})
慕侠2389804
相关分类