example.js 934 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict'
  2. const path = require('path')
  3. const { db, utils } = require('./lib')
  4. const setup = async () => {
  5. // Connect to the database
  6. const connection = await db.connect('mongodb://diran.univ-littoral.fr:27017/webexpe')
  7. // Find every documents being experiment data
  8. const res = await db.findCustom({
  9. msgId: 'EXPERIMENT_DATA'
  10. })
  11. // Output to console (Do this if you want to pipe to another command!)
  12. console.log(res)
  13. console.log(`Found ${res.length} documents matching your request.`)
  14. // Save the results to a JSON file
  15. const filePath = path.resolve(__dirname, 'searches', `search-${Date.now()}.json`)
  16. // `res` = search results, `filePath` = output file, `true` = JSON will be pretty-printed (human-readable)
  17. await utils.outputToFile(res, filePath, true)
  18. console.log(`Your search results were saved to ${filePath}`)
  19. // Disconnect from the database
  20. await db.disconnect(connection)
  21. }
  22. setup()