繁体   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