SERVER-121083: Update vector_search_nonexistent_collection.js to succeed for explain queries in sharded clusters (#49158)
GitOrigin-RevId: 894fbe9284e2cf21bcdc3f8f3f9faf6c22ea76ba
This commit is contained in:
committed by
MongoDB Bot
parent
f19b327000
commit
df83668d91
@@ -1,11 +1,14 @@
|
||||
/**
|
||||
* Tests that $vectorSearch handles non-existent collections correctly.
|
||||
* - Non-explain queries should return no documents (EOF from doGetNext) even if UUID does not exist.
|
||||
* - Explain queries should fail due to missing UUID.
|
||||
* - Explain on non-sharded (mongod): fails with 65152 or 7828001 due to missing UUID.
|
||||
* - Explain on sharded (mongos): succeeds with EOF plan.
|
||||
*/
|
||||
|
||||
import {FixtureHelpers} from "jstests/libs/fixture_helpers.js";
|
||||
import {describe, it} from "jstests/libs/mochalite.js";
|
||||
|
||||
const testDb = db.getSiblingDB(jsTestName());
|
||||
const nonExistentCollName = jsTestName();
|
||||
|
||||
describe("$vectorSearch on non-existent collection", function () {
|
||||
@@ -23,13 +26,13 @@ describe("$vectorSearch on non-existent collection", function () {
|
||||
];
|
||||
|
||||
// Non-explain query should succeed but return no documents
|
||||
const res = assert.commandWorked(db.runCommand({aggregate: nonExistentCollName, pipeline, cursor: {}}));
|
||||
const res = assert.commandWorked(testDb.runCommand({aggregate: nonExistentCollName, pipeline, cursor: {}}));
|
||||
|
||||
assert.eq(res.cursor.firstBatch, [], "Expected empty result set for vector search on non-existent collection");
|
||||
assert.eq(res.cursor.id, 0, "Expected cursor to be exhausted");
|
||||
});
|
||||
|
||||
it("should fail with error for explain query with extension vector search", function () {
|
||||
it("should fail with error for explain query on non-sharded; succeed with EOF on sharded", function () {
|
||||
const pipeline = [
|
||||
{
|
||||
$vectorSearch: {
|
||||
@@ -42,12 +45,21 @@ describe("$vectorSearch on non-existent collection", function () {
|
||||
},
|
||||
];
|
||||
|
||||
// Legacy vector search explain query should fail with error 7828001 (a valid collection is needed for explain).
|
||||
const res = testDb.runCommand({aggregate: nonExistentCollName, pipeline, cursor: {}, explain: true});
|
||||
|
||||
if (FixtureHelpers.isMongos(testDb)) {
|
||||
// Sharded: returns EOF explain for non-existent namespace.
|
||||
assert.commandWorked(res);
|
||||
assert.eq(res.queryPlanner.winningPlan.stage, "EOF", res);
|
||||
assert.eq(res.queryPlanner.winningPlan.type, "nonExistentNamespace", res);
|
||||
} else {
|
||||
// Non-sharded: explain requires collection UUID for $vectorSearch. Legacy vector search explain query should fail with error 7828001 (a valid collection is needed for explain).
|
||||
// Extension vector search should fail with error 65152 (EXPLAIN_COLLECTION_UUID_REQUIRED).
|
||||
assert.commandFailedWithCode(
|
||||
db.runCommand({aggregate: nonExistentCollName, pipeline, cursor: {}, explain: true}),
|
||||
res,
|
||||
[65152, 7828001],
|
||||
"Expected error for missing UUID when explaining extension vector search on non-existent collection",
|
||||
"Expected error for missing UUID when explaining vector search on non-existent collection",
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user