im building a chatbot and i want to filter a MongoDb database with the input of the users
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
}
i've tried to do it like this
this.fetchDataFromDataSource({ channel: this.channel, collectionName: "62a985781cd96396e4e1cba3_test", filter:{ kw1: words
} }).then((result) => {
console.log(result)
})
when the input is only a word it works well but when i send more than one word it doesn't behave as expected, how im supposed to do it?
Try using the $in
operator:
this.fetchDataFromDataSource({
channel: this.channel,
collectionName: '62a985781cd96396e4e1cba3_test',
filter: { kw1: { $in: words } },
}).then((result) => {
console.log(result);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.