summaryrefslogtreecommitdiff
path: root/jstests/aggregation/sources/match/text_search_requires_index.js
blob: ff62fa1bea29f523116bb9d5b148ffa7c6dda159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Tests that text search requires a text index.
// TODO: Reenable test on passthroughs with sharded collections as part of SERVER-38996.
// @tags: [assumes_unsharded_collection]
(function() {
"use strict";

load("jstests/aggregation/extras/utils.js");  // For "assertErrorCode".

const coll = db.coll;
const from = db.from;

coll.drop();
from.drop();

const textPipeline = [{$match: {$text: {$search: "foo"}}}];

const pipeline = [
        {
          $lookup: {
              pipeline: textPipeline,
              from: from.getName(),
              as: "c",
          }
        },
    ];

assert.commandWorked(coll.insert({_id: 1}));
assert.commandWorked(from.insert({_id: 100, a: "foo"}));

// Fail without index.
assertErrorCode(from, textPipeline, ErrorCodes.IndexNotFound);
assertErrorCode(coll, pipeline, ErrorCodes.IndexNotFound);

assert.commandWorked(from.createIndex({a: "text"}));

// Should run when you have the text index.
assert.eq(from.aggregate(textPipeline).itcount(), 1);
assert.eq(coll.aggregate(pipeline).itcount(), 1);
}());