如果名称包含mongo或mongoose中的所有其他文档关键字,如何查找文档?

时间:2017-01-18 02:35:47

标签: node.js mongodb mongoose

我有一个包含2列的集合:

name: string
keywords: array

有些文件是这样的:

{ name: 'foo is good', keywords: ['foo', 'fo', 'fooo'] }

当我使用name='bar is good'创建新文档时,如果name包含所有其他文档关键字,我想查找文档,如下所示:

  // new document with name='bar is bad'
  { name: 'bar is good', keywords: ['bar', 'bars', 'barr'] } // find this, keywords have 'bar'
  { name: 'baz is good', keywords: ['baz', 'is', 'good'] } // find this, keywords have 'is'
  { name: 'hello world', keywords: ['hello', 'world'] } // don't find this, keywords don't match any words in name

如何在mongonDB或mongoose中编写查找同步?感谢。

0 个答案:

没有答案