構造を持つ 130k 要素のコレクション:
{
"tags": ["restaurant", "john doe"]
}
「restaurant」タグが付いたドキュメントは 40,000 件ありますが、「john doe」タグが付いているドキュメントは 2 つだけです。したがって、次のクエリは異なります。
// 0.100 seconds (40.000 objects scanned)
{"tags": {$all: [/^restaurant/, /^john doe/]}}
// 0.004 seconds (2 objects scanned)
{"tags": {$all: [/^john doe/, /^restaurant/]}}
クライアントでタグをソートせずにクエリを最適化する方法はありますか? 私が今想像できる唯一の方法は、検索配列の先頭にあまり頻繁にタグを付けないことです。