mongodb.js 976 B

123456789101112131415161718192021222324252627282930313233
  1. import Metrics from '@overleaf/metrics'
  2. import MongoUtils from '@overleaf/mongo-utils'
  3. import Settings from '@overleaf/settings'
  4. import mongodb from 'mongodb-legacy'
  5. const { MongoClient, ObjectId } = mongodb
  6. /**
  7. * @import { ProjectHistoryFailure } from './mongo-types'
  8. */
  9. export { ObjectId }
  10. export const mongoClient = new MongoClient(
  11. Settings.mongo.url,
  12. Settings.mongo.options
  13. )
  14. const mongoDb = mongoClient.db()
  15. Metrics.mongodb.monitor(mongoClient)
  16. async function cleanupTestDatabase() {
  17. await MongoUtils.cleanupTestDatabase(mongoClient)
  18. }
  19. export const db = {
  20. deletedProjects: mongoDb.collection('deletedProjects'),
  21. projects: mongoDb.collection('projects'),
  22. /** @type {mongodb.Collection<ProjectHistoryFailure>} */
  23. projectHistoryFailures: mongoDb.collection('projectHistoryFailures'),
  24. projectHistoryLabels: mongoDb.collection('projectHistoryLabels'),
  25. projectHistorySyncState: mongoDb.collection('projectHistorySyncState'),
  26. cleanupTestDatabase,
  27. }