mongo.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const loggerFactory = require('@alias/logger');
  2. const logger = loggerFactory('growi:routes:apiv3:mongo'); // eslint-disable-line no-unused-vars
  3. const express = require('express');
  4. const router = express.Router();
  5. /**
  6. * @swagger
  7. * tags:
  8. * name: Mongo
  9. */
  10. module.exports = (crowi) => {
  11. /**
  12. * @swagger
  13. *
  14. * /mongo/collections:
  15. * get:
  16. * tags: [Mongo]
  17. * description: get mongodb collections names
  18. * responses:
  19. * 200:
  20. * description: a list of collections in mongoDB
  21. * content:
  22. * application/json:
  23. * schema:
  24. * properties:
  25. * collections:
  26. * type: array
  27. * items:
  28. * type: string
  29. */
  30. router.get('/collections', async(req, res) => {
  31. const collections = Object.values(crowi.models).map(model => model.collection.collectionName);
  32. // TODO: use res.apiv3
  33. return res.json({
  34. ok: true,
  35. collections: [...new Set(collections)], // remove duplicates
  36. });
  37. });
  38. return router;
  39. };