0
我正在使用Node,Express,Mongoose和Mongodb爲Web應用程序創建後端。我試圖在名稱字段和標籤數組上運行部分用戶配置文件的部分搜索,以便「re」將返回包含「red」和「blueish」的標籤數組或名稱的配置文件將返回具有a標籤數組或包含「藍色」的名稱Mongoose - 如何搜索部分字符串匹配,然後按分數對結果進行排序?
我找到了添加正則表達式的語法。沿線的東西:
Profile.find(.0
{ "tags": { "$regex": "re", "$options": "i" } },
function(err,docs) {
str = JSON.stringify(docs, null, 4);
console.log(str)
}
);
我也試圖給他們打分並對結果進行排序。我發現了另一個堆棧溢出的職位,是沿着線:
Profile.find({ "$text": { "$search": input } })
.select({ "score": { "$meta": "textScore" } })
.sort({ "score": { "$meta": "textScore" } })
.exec(function(err,result) {
str = JSON.stringify(result, null, 4);
console.log(str)
}
);
但閱讀文檔後,我仍然是一個模糊的,但如何將兩個概念結合起來。有小費嗎?
太棒了!感謝Rob! – Indigo