Skip to content

Commit

Permalink
UBER-1198: Upgrade to mongo 7
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <[email protected]>
  • Loading branch information
haiodo committed Jan 30, 2024
1 parent 0d822f4 commit 844c5c2
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 1,226 deletions.
1,458 changes: 257 additions & 1,201 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
mongodb:
image: mongo
image: 'mongo:7-jammy'
container_name: mongodb
environment:
- PUID=1000
Expand Down
2 changes: 1 addition & 1 deletion dev/tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"got": "^11.8.3",
"libphonenumber-js": "^1.9.46",
"mime-types": "~2.1.34",
"mongodb": "^4.11.0",
"mongodb": "^6.3.0",
"ws": "^8.10.0",
"xml2js": "~0.4.23"
}
Expand Down
12 changes: 6 additions & 6 deletions dev/tool/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ export async function fixSkills (
tag: t._id
})) as TagReference[]
const ids = references.map((r) => r._id)
await db.collection(DOMAIN_TAGS).deleteMany({ _id: { $in: ids } })
await db.collection(DOMAIN_TAGS).deleteOne({ _id: t._id })
await db.collection<Doc>(DOMAIN_TAGS).deleteMany({ _id: { $in: ids } })
await db.collection<Doc>(DOMAIN_TAGS).deleteOne({ _id: t._id })
}
}
await fixCount()
Expand All @@ -588,8 +588,8 @@ export async function fixSkills (
tag: t._id
})) as TagReference[]
const ids = references.map((r) => r._id)
await db.collection(DOMAIN_TAGS).deleteMany({ _id: { $in: ids } })
await db.collection(DOMAIN_TAGS).deleteOne({ _id: t._id })
await db.collection<Doc>(DOMAIN_TAGS).deleteMany({ _id: { $in: ids } })
await db.collection<Doc>(DOMAIN_TAGS).deleteOne({ _id: t._id })
}
console.log('DONE 6 STEP')
}
Expand All @@ -610,8 +610,8 @@ export async function fixSkills (
tag: t._id
})) as TagReference[]
const ids = references.map((r) => r._id)
await db.collection(DOMAIN_TAGS).deleteMany({ _id: { $in: ids } })
await db.collection(DOMAIN_TAGS).deleteOne({ _id: t._id })
await db.collection<Doc>(DOMAIN_TAGS).deleteMany({ _id: { $in: ids } })
await db.collection<Doc>(DOMAIN_TAGS).deleteOne({ _id: t._id })
}
}
await fixCount()
Expand Down
2 changes: 1 addition & 1 deletion pods/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@hcengineering/account": "^0.6.0",
"@hcengineering/platform": "^0.6.9",
"@hcengineering/core": "^0.6.28",
"mongodb": "^4.11.0",
"mongodb": "^6.3.0",
"koa": "^2.13.1",
"koa-router": "^12.0.1",
"koa-bodyparser": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion pods/backup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@hcengineering/platform": "^0.6.9",
"mongodb": "^4.11.0",
"mongodb": "^6.3.0",
"@hcengineering/server-tool": "^0.6.0",
"@hcengineering/server-token": "^0.6.7",
"@hcengineering/client": "^0.6.14",
Expand Down
2 changes: 1 addition & 1 deletion server/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prettier-plugin-svelte": "^3.1.0"
},
"dependencies": {
"mongodb": "^4.11.0",
"mongodb": "^6.3.0",
"@hcengineering/platform": "^0.6.9",
"@hcengineering/core": "^0.6.28",
"@hcengineering/contact": "^0.6.20",
Expand Down
4 changes: 2 additions & 2 deletions server/account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function withProductId (productId: string, query: Filter<Workspace>): Filter<Wor
* @returns
*/
export async function getWorkspace (db: Db, productId: string, workspace: string): Promise<Workspace | null> {
return await db.collection(WORKSPACE_COLLECTION).findOne<Workspace>(withProductId(productId, { workspace }))
return await db.collection<Workspace>(WORKSPACE_COLLECTION).findOne(withProductId(productId, { workspace }))
}

function toAccountInfo (account: Account): AccountInfo {
Expand All @@ -196,7 +196,7 @@ async function getAccountInfo (db: Db, email: string, password: string): Promise
if (account === null) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account: email }))
}
if (!verifyPassword(password, account.hash.buffer, account.salt.buffer)) {
if (!verifyPassword(password, Buffer.from(account.hash.buffer), Buffer.from(account.salt.buffer))) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.InvalidPassword, { account: email }))
}
return toAccountInfo(account)
Expand Down
2 changes: 1 addition & 1 deletion server/collaborator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@hocuspocus/transformer": "^2.9.0",
"@tiptap/core": "^2.1.12",
"@tiptap/html": "^2.1.12",
"mongodb": "^4.11.0",
"mongodb": "^6.3.0",
"yjs": "^13.5.52",
"y-prosemirror": "^1.2.1",
"express": "^4.17.1",
Expand Down
8 changes: 5 additions & 3 deletions server/collaborator/src/storage/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

import { MeasureContext, toWorkspaceString } from '@hcengineering/core'
import { Doc, MeasureContext, Ref, toWorkspaceString } from '@hcengineering/core'
import { Transformer } from '@hocuspocus/transformer'
import { MongoClient } from 'mongodb'
import { Doc as YDoc } from 'yjs'
Expand Down Expand Up @@ -66,10 +66,12 @@ export class MongodbStorageAdapter implements StorageAdapter {
return await this.ctx.with('load-document', {}, async (ctx) => {
const doc = await ctx.with('query', {}, async () => {
const db = this.mongodb.db(toWorkspaceString(context.workspaceId))
return await db.collection(objectDomain).findOne({ _id: objectId }, { projection: { [objectAttr]: 1 } })
return await db
.collection<Doc>(objectDomain)
.findOne({ _id: objectId as Ref<Doc> }, { projection: { [objectAttr]: 1 } })
})

const content = doc !== null && objectAttr in doc ? (doc[objectAttr] as string) : ''
const content = doc !== null && objectAttr in doc ? ((doc as any)[objectAttr] as string) : ''

return await ctx.with('transform', {}, () => {
return this.transformer.toYdoc(content, objectAttr)
Expand Down
2 changes: 1 addition & 1 deletion server/mongo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"@hcengineering/core": "^0.6.28",
"@hcengineering/platform": "^0.6.9",
"@hcengineering/server-core": "^0.6.1",
"mongodb": "^4.11.0"
"mongodb": "^6.3.0"
}
}
8 changes: 4 additions & 4 deletions server/mongo/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ abstract class MongoAdapterBase implements DbAdapter {
return this.stripHash(
this.stripHash(
await this.db
.collection(domain)
.collection<Doc>(domain)
.find<Doc>({ _id: { $in: docs } })
.toArray()
)
Expand Down Expand Up @@ -783,7 +783,7 @@ abstract class MongoAdapterBase implements DbAdapter {
}

async clean (domain: Domain, docs: Ref<Doc>[]): Promise<void> {
await this.db.collection(domain).deleteMany({ _id: { $in: docs } })
await this.db.collection<Doc>(domain).deleteMany({ _id: { $in: docs } })
}
}

Expand Down Expand Up @@ -1089,7 +1089,7 @@ class MongoAdapter extends MongoAdapterBase {
} as unknown as UpdateFilter<Document>,
{ returnDocument: 'after' }
)
return { object: result.value }
return { object: result?.value ?? undefined }
}
return {
raw,
Expand Down Expand Up @@ -1129,7 +1129,7 @@ class MongoAdapter extends MongoAdapterBase {
const result = await this.db
.collection(domain)
.findOneAndUpdate(filter, update, { returnDocument: 'after' })
return { object: result.value }
return { object: result?.value ?? undefined }
}
: async () => await this.db.collection(domain).updateOne(filter, update)

Expand Down
2 changes: 1 addition & 1 deletion server/tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"prettier-plugin-svelte": "^3.1.0"
},
"dependencies": {
"mongodb": "^4.11.0",
"mongodb": "^6.3.0",
"@hcengineering/platform": "^0.6.9",
"@hcengineering/core": "^0.6.28",
"@hcengineering/contact": "^0.6.20",
Expand Down
2 changes: 1 addition & 1 deletion server/tool/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ export class MigrateClientImpl implements MigrationClient {
}

async deleteMany<T extends Doc>(domain: Domain, query: DocumentQuery<T>): Promise<void> {
await this.db.collection(domain).deleteMany(query)
await this.db.collection<Doc>(domain).deleteMany(query as any)
}
}
2 changes: 1 addition & 1 deletion tests/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
mongodb:
image: mongo
image: 'mongo:7-jammy'
command: mongod --port 27018
environment:
- PUID=1000
Expand Down

0 comments on commit 844c5c2

Please sign in to comment.