mongodb find by multiple array items

前端 未结 1 913
一整个雨季
一整个雨季 2020-11-27 13:15

If I have a record like this;

{
  \"text\": \"text goes here\",
  \"words\": [\"text\", \"goes\", \"here\"]
}

How can I match multiple word

相关标签:
1条回答
  • 2020-11-27 13:44

    Depends on whether you're trying to find documents where words contains both elements (text and here) using $all:

    db.things.find({ words: { $all: ["text", "here"] }});
    

    or either of them (text or here) using $in:

    db.things.find({ words: { $in: ["text", "here"] }});
    
    0 讨论(0)
提交回复
热议问题