mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-12 19:30:52 +00:00
UBER-266: Fix mongo exceptions (#3267)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
4fad67b6a4
commit
b95066d71a
@ -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
|
||||
}
|
||||
|
@ -617,14 +617,23 @@ abstract class MongoAdapterBase implements DbAdapter {
|
||||
async update (domain: Domain, operations: Map<Ref<Doc>, DocumentUpdate<Doc>>): Promise<void> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user