Q: Closing mongoose db connection erases schema I got a weird behavior with mongoose, it seems that closing the db connection after saving my schema erases it.
Here's my schema brand.js:
var brandSchema = new db.Schema({

  id: {type: String, required: true, index: {unique: true}},
  products: [String]
});

I execute the following script to populate my database (important precision: before executing the script, my brand table is not defined in the DB):
var async = require('async');

//Get config
var middlewares = require('./middlewares');
var config = require('./config');

//Load model
require('./models/brand');
var db = middlewares.db(config);


// Load brand.json
var brands = require('./brands.json');


// Save each brand in the database
async.each(Object.keys(brands), function(brandId, callback){

  var brand = new Brand({id:  brandId, products: brands[brandsId]);

  brand.save(function(err){
    if(err) console.log(err);
    else console.log('brand ' + brand.id + ' added');
      callback();
  });

}, function(){
  //Properly close the connection so the script can terminate
  db.connection.close();
});

This script gives the following logs:
Mongoose: brand.ensureIndex({ id: 1 }) { safe: undefined, background: true, uni
que: true }
Mongoose: brand.insert({ __v: 0, products: [ 'phone', 'tv'], _id: ObjectId(
"54524f612245da0c2f0d2ba7"), id: 'samsung' }) {}
Mongoose: brand.insert({ __v: 0, products: [ 'food', 'beverages' ], _id: ObjectId(
"54524f612245da0c2f0d2ba8"), id: '' }) {}

The first line of the logs suggests that an index id is created with the right parameters. But when I look into the DB, my brands are saved but the brand schema is empty. However, if I remove db.connection.close(), brands are still saved and the schema is saved like defined in Brand.
I don't really understand why. Could it be because of buffered data not sent to the db ?
