Files
mongo/jstests/with_mongot/e2e/empty_collection.js
Ted Tuckman 5ad6f9d266 SERVER-109126 Add cursor check to InternalMongotRemote::doGetNext (#40140)
Co-authored-by: Joshua Siegel <josh.siegel@mongodb.com>
GitOrigin-RevId: 7e49356f7a90f32fd8094ec5aa350c4677873304
2025-09-04 16:47:24 +00:00

22 lines
963 B
JavaScript

// This test confirms behavior when a search query is executed on an empty and non-existent collection.
import {createSearchIndex, dropSearchIndex} from "jstests/libs/search.js";
let collName = jsTestName();
let coll = db[collName];
db.createCollection(collName);
coll.insertOne({_id: 1, a: "bar"});
// Create search index.
const indexName = collName + "_index";
createSearchIndex(coll, {name: indexName, definition: {mappings: {dynamic: true}}});
// Delete the document (collection still exists) and check that a search query correctly returns no results.
coll.deleteOne({_id: 1});
let result = coll.aggregate([{$search: {index: indexName, text: {path: "a", query: "bar"}}}]).toArray();
assert.eq(0, result.length, result);
// Drop the collection and check that a search query correctly returns no results.
coll.drop();
result = coll.aggregate([{$search: {index: indexName, text: {path: "a", query: "bar"}}}]).toArray();
assert.eq(0, result.length, result);