[英]Filter on mongoDb an array of strings
我正在構建一個聊天機器人,我想用用戶的輸入過濾一個 MongoDb 數據庫
words=["hello","price","bye"]
{
"Lang": "en",
"kw1": [
"price"
],
"Keyword Group 2": [
"test"
],
"Keyword Group 3": [
"res"
],
"Type": "Text",
"Text": "aaaaaAAAAAaaa",
"createdAt": 1662724328993,
"etag": "d-Zwyn11c6q6DfK+AV6RVxl9i7OJQ",
"_version": 2,
"updatedAt": 1662724336488
}
我試過這樣做
this.fetchDataFromDataSource({ channel: this.channel, collectionName: "62a985781cd96396e4e1cba3_test", filter:{ kw1: words
} }).then((result) => {
console.log(result)
})
當輸入只是一個單詞時,它運行良好,但是當我發送多個單詞時,它的行為不符合預期,我應該怎么做?
嘗試使用$in
運算符:
this.fetchDataFromDataSource({
channel: this.channel,
collectionName: '62a985781cd96396e4e1cba3_test',
filter: { kw1: { $in: words } },
}).then((result) => {
console.log(result);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.