mongodb.js 595 B

12345678910111213141516171819202122232425
  1. const Settings = require('@overleaf/settings')
  2. const { MongoClient, ObjectId } = require('mongodb')
  3. const mongoClient = new MongoClient(Settings.mongo.url)
  4. const mongoDb = mongoClient.db()
  5. const db = {
  6. docs: mongoDb.collection('docs'),
  7. docSnapshots: mongoDb.collection('docSnapshots'),
  8. projects: mongoDb.collection('projects'),
  9. }
  10. async function healthCheck() {
  11. const res = await mongoDb.command({ ping: 1 })
  12. if (!res.ok) {
  13. throw new Error('failed mongo ping')
  14. }
  15. }
  16. module.exports = {
  17. db,
  18. ObjectId,
  19. mongoClient,
  20. healthCheck: require('util').callbackify(healthCheck),
  21. }