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; }