mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-03 23:18:01 -05:00
c371732e6e
[web] Use constructor for ObjectId GitOrigin-RevId: 9eb8b377ea599605b72af237d1ab12f4d8287162
40 lines
933 B
JavaScript
40 lines
933 B
JavaScript
const { ObjectId } = require('mongodb')
|
|
const { waitForDb, db } = require('../../../app/src/infrastructure/mongodb')
|
|
const { getMongoClient } = require('../../../app/src/infrastructure/Mongoose')
|
|
|
|
async function main() {
|
|
try {
|
|
await waitForDb()
|
|
} catch (err) {
|
|
console.error('Cannot connect to mongodb')
|
|
throw err
|
|
}
|
|
try {
|
|
await testTransactions()
|
|
} catch (err) {
|
|
console.error("Mongo instance doesn't support transactions")
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function testTransactions() {
|
|
const mongoClient = await getMongoClient()
|
|
const session = mongoClient.startSession()
|
|
try {
|
|
await session.withTransaction(async () => {
|
|
await db.users.findOne({ _id: new ObjectId() }, { session })
|
|
})
|
|
} finally {
|
|
await session.endSession()
|
|
}
|
|
}
|
|
|
|
main()
|
|
.then(() => {
|
|
console.error('Mongodb is up.')
|
|
process.exit(0)
|
|
})
|
|
.catch(err => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|