Parcourir la source

Fixed not wanted logging

rigwild il y a 4 ans
Parent
commit
ddea01ba89
3 fichiers modifiés avec 8 ajouts et 8 suppressions
  1. 1 1
      README.md
  2. 2 0
      example.js
  3. 5 7
      lib/db.js

+ 1 - 1
README.md

@@ -11,6 +11,6 @@ npm i git+https://gogs@gogs.univ-littoral.fr/Prise3D/webexpe-data-extract
 See [`/example.js`](./example.js)
 
 ## API
-See [`/lib/db.js#L83-93`](./lib/db.js#L83-93)
+See [`/lib/db.js#L83-L94`](./lib/db.js#L83-L94)
 
 Every functions should be auto-completable in your editor.

+ 2 - 0
example.js

@@ -6,6 +6,7 @@ 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({
@@ -26,6 +27,7 @@ const setup = async () => {
 
   // Disconnect from the database
   await db.disconnect(connection)
+  console.log('The database connection was destroyed.')
 }
 
 setup()

+ 5 - 7
lib/db.js

@@ -19,7 +19,6 @@ module.exports = {
   async connect(mongoConnectionString) {
     const connection = await mongoose.connect(mongoConnectionString, { useNewUrlParser: true, useFindAndModify: false })
     mongoose.connection.on('error', err => console.log(err))
-    console.log('The database connection was established.')
     return connection
   },
 
@@ -28,9 +27,8 @@ module.exports = {
    * @param {Object} connectionObj Connecion object
    * @returns {Promise<void>} The connection was destroyed
    */
-  async disconnect(connectionObj) {
-    await connectionObj.disconnect()
-    console.log('The database connection was destroyed.')
+  disconnect(connectionObj) {
+    return connectionObj.disconnect()
   },
 
 
@@ -43,7 +41,7 @@ module.exports = {
    */
   async add(dataObj) {
     const doc = await DataModel.create({ data: dataObj })
-    console.log(`New document was added. id=${doc.id}`)
+    // console.log(`New document was added. id=${doc.id}`)
     return doc
   },
 
@@ -54,7 +52,7 @@ module.exports = {
    */
   async del(dataId) {
     const doc = await DataModel.findByIdAndDelete(dataId)
-    console.log(`A document was deleted. id=${doc.id}`)
+    // console.log(`A document was deleted. id=${doc.id}`)
   },
 
   /**
@@ -65,7 +63,7 @@ module.exports = {
    */
   async update(dataId, newDataObj) {
     const doc = await DataModel.findByIdAndUpdate(dataId, { $set: { data: newDataObj } }, { new: true })
-    console.log(`A document was updated. id=${doc.id}`)
+    // console.log(`A document was updated. id=${doc.id}`)
     return doc
   },