mongodb query subset of an array

后端 未结 3 1258
清酒与你
清酒与你 2021-02-06 10:03

I have a field _keywords which is an array of strings. I want to get documents of which _keywords are super-set of the query array.

For example

3条回答
  •  有刺的猬
    2021-02-06 10:49

    Short answer: $all operator.
    To query documents with array with superset of ['foo1', 'foo2'], use:
    db.article.find( { '_keywords': { $all: ['foo1', 'foo2'] } } );

提交回复
热议问题