From 39e682d6d44e3bb19292d8c22bf70a4862d40ffa Mon Sep 17 00:00:00 2001 From: Henrik Vester Date: Tue, 9 Jun 2026 11:26:45 +0200 Subject: [PATCH] Fix vector search index creation failing with BadValue on Atlas Local When updateSearchIndex is called for a new vector search index (fields-based, no mappings), Atlas Local validates the definition before checking existence and returns BadValue ("mappings is required") instead of IndexNotFound. This prevented the createSearchIndex fallback from ever being triggered. Fix by also catching BadValue for vectorSearch-type definitions. --- bin/mongodb-sync-indices.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/mongodb-sync-indices.js b/bin/mongodb-sync-indices.js index 7421032..6ef27da 100644 --- a/bin/mongodb-sync-indices.js +++ b/bin/mongodb-sync-indices.js @@ -69,17 +69,16 @@ function createSearchIndices(collection, definitions) { return Promise.all( Object.entries(definitions) .map(async ([ name, definition ]) => { + const type = "mappings" in definition ? "search" : "vectorSearch"; try { await collection.updateSearchIndex(name, definition); } catch (error) { if ( - error instanceof MongoServerError && error.codeName === "IndexNotFound" + error instanceof MongoServerError && + (error.codeName === "IndexNotFound" || + (type === "vectorSearch" && error.codeName === "BadValue")) ) { - await collection.createSearchIndex({ - name, - type: "mappings" in definition ? "search" : "vectorSearch", - definition, - }); + await collection.createSearchIndex({ name, type, definition }); } else { throw error; }