-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
33 lines (24 loc) · 1.02 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict'
const path = require('path')
const { db, utils } = require('./lib')
const setup = async () => {
// Connect to the database
const connection = await db.connect('mongodb://diran.univ-littoral.fr:27017/webexpe')
console.log('The database connection was established.')
// Find every documents being experiment data
const res = await db.findCustom({
msgId: 'EXPERIMENT_DATA'
})
// Output to console (Do this if you want to pipe to another command!)
console.log(res)
console.log(`Found ${res.length} documents matching your request.`)
// Save the results to a JSON file
const filePath = path.resolve(__dirname, 'searches', `search-${Date.now()}.json`)
// `res` = search results, `filePath` = output file, `true` = JSON will be pretty-printed (human-readable)
await utils.outputToFile(res, filePath, true)
console.log(`Your search results were saved to ${filePath}`)
// Disconnect from the database
await db.disconnect(connection)
console.log('The database connection was destroyed.')
}
setup()