title: mongoose creating null document after using module export in express
body: <p>I was recently using a function to upload files to a mongodb database successfully. However after moving those functions into a file (to clean up) and exporting that file then requiring it in my route, the database now creates documents with only null values like so:</p>
  
  <pre><code>_id:ObjectId("xxxxxxxxxxxxxxx")
  name:null,
  value:null,
  image:null,
  desc:null
  </code></pre>
  
  <p>I don't know what might be causing this, I am logging the argument object that i'm trying to insert from inside the function 'insertProducts' and the item.name is not null. Sorry I'm new to mongodb :/
  maybe someone can point me in the right direction?</p>
  
  <p>CRUD.js</p>
  
  <pre><code>
  const mongodb = require('mongodb');
  const MongoClient = mongodb.MongoClient;
  
  
  const removeProducts = function(req,res){
      MongoClient.connect('mongodb://localhost', (err, client) =&gt; {
        if (err) {
          throw err;
        }
        let db = client.db('account-app');
        let products = db.collection('products');
        let users = db.collection('users');
  
        try{
          products.remove({ _id: req.body.id }, function(err) {
            if (!err) {
                    console.log('removed item')
            }
        });
        }
        catch(err){
          console.log('Error while inserting', err)
        }
        client.close()
        res.redirect('/addItems')
  
      })
    }
  
  
    const insertProducts = function(item,res){
  
      console.log("item name",item.name)
      MongoClient.connect('mongodb://localhost', (err, client) =&gt; {
        if (err) {
          throw err;
        }
        let db = client.db('account-app');
        let products = db.collection('products');
  
        try{
          products.insertOne(item)
          console.log('item inserted')
        }
        catch(err){
          console.log('Error while inserting', err)
        }
        client.close()
        res.redirect('/admin/addItems')
  
      })
    }
  
    module.exports={removeProducts: removeProducts, insertProducts: insertProducts}
  </code></pre>
  
  <p>my admin route that requires the crud functions</p>
  
  <pre><code>const crudOps = require('../utils/admin/CRUD') //require CRUD functions
  
  // Adding new items
  // --------------------------------------------------
  router.post('/addNewItems', (req, res, next) =&gt; {
  console.log(req.body.name)
  
  let item = {
    name:req.body.name,
    file: binary(req.files.image.data),
    value: req.body.value,
    desc: req.body.desc
  }
  
  crudOps.insertProducts(item, res)
  });
  </code></pre>