diff --git a/server/core/src/indexer/summary.ts b/server/core/src/indexer/summary.ts index 0215136525..c2a8882f2a 100644 --- a/server/core/src/indexer/summary.ts +++ b/server/core/src/indexer/summary.ts @@ -223,10 +223,8 @@ export async function extractIndexedValues ( continue } // Check if attribute is indexable - let keyAttr: AnyAttribute - try { - keyAttr = hierarchy.getAttribute(_class, attr) - } catch (err: any) { + const keyAttr: AnyAttribute | undefined = hierarchy.findAttribute(_class, attr) + if (keyAttr === undefined) { // Skip if there is no attribute. continue } diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index 26927a3df7..c5a7ec76e5 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -617,14 +617,23 @@ abstract class MongoAdapterBase implements DbAdapter { async update (domain: Domain, operations: Map, DocumentUpdate>): Promise { const coll = this.db.collection(domain) - try { - // remove old and insert new ones - const ops = Array.from(operations.entries()) - if (ops.length > 0) { - const part = ops.splice(0, 500) + // remove old and insert new ones + const ops = Array.from(operations.entries()) + let skip = 500 + while (ops.length > 0) { + const part = ops.splice(0, skip) + try { await coll.bulkWrite( part.map((it) => { const { $unset, ...set } = it[1] as any + if ($unset !== undefined) { + for (const k of Object.keys(set)) { + if ($unset[k] === '') { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete + delete $unset[k] + } + } + } return { updateOne: { filter: { _id: it[0] }, @@ -636,9 +645,13 @@ abstract class MongoAdapterBase implements DbAdapter { } }) ) + } catch (err: any) { + if (skip !== 1) { + ops.push(...part) + skip = 1 // Let's update one by one, to loose only one failed variant. + } + console.error(err) } - } catch (err: any) { - console.error(err) } }