MongoDB,php - 查找与$ text搜索数组不匹配的所有文档

  1. MongoDB (Title - is text index):

sample data:

{_id: 1, Title: 'Some title'}
{_id: 2, Title: 'Some word'}
{_id: 3, Title: 'Some bad word'}
{_id: 4, Title: 'No stop word'}
{_id: 5, Title: 'No more title'}
{_id: 6, Title: 'Some stop'}
  1. Array of MongoDB $text search request's:

sample data:

[
'some -bad',
'word -bad',
'good -bad',
'"some word" -bad',
]

Need to find all MongoDB docs which don't match any of this $text search from array.

Trouble in case of big data.

The approach i take to solve:

  • find all _id's for first search,
  • then for 2nd, etc..
  • As result will get a huge array of _id's (Example: $not_matched_ids).
  • Then I need do something with this data and source DB. For example, delete all records from DB which in $not_matched_ids. But $not_matched_ids is huge array and DB is big.

MongoDB $in - isn't good solution. Is there another algorithm?