mongodb.js 427 B

12345678910111213141516171819
  1. const Settings = require('settings-sharelatex')
  2. const { MongoClient, ObjectId } = require('mongodb')
  3. const clientPromise = MongoClient.connect(Settings.mongo.url)
  4. const dbPromise = clientPromise.then((client) => client.db())
  5. async function getCollection(name) {
  6. return (await dbPromise).collection(name)
  7. }
  8. async function waitForDb() {
  9. await clientPromise
  10. }
  11. module.exports = {
  12. ObjectId,
  13. getCollection,
  14. waitForDb
  15. }