簡體   English   中英

過濾 mongoDb 字符串數組

[英]Filter on mongoDb an array of strings

我正在構建一個聊天機器人,我想用用戶的輸入過濾一個 MongoDb 數據庫

words=["hello","price","bye"]

我的數據庫就是這樣D b

{
  "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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM