These are chat archives for Automattic/mongoose

Feb 2017
kailash k yogeshwar
Feb 13 2017 05:30
i am trying save the image uploaded from postman as base64 in mongodb so the 512kB image will have the equivalent base64 string in db everything is fine on local machine but it takes alot of time when deployed on server should be image be compressed more and then stored and how to reduce the latency due to this huge image data
Isak La Fleur Engdahl
Feb 13 2017 17:13
Hello! I have a question how to best disconnect from the database.
Im new to mongoose, btw. :)

var mongoose = require("mongoose");
var fs = require('fs');
mongoose.Promise = require('bluebird');


var db = mongoose.connection;

db.on('error', console.error.bind(console, 'connection error:'));

db.once('open', function() {
// we're connected!

// create db schema
var CdSchema = new mongoose.Schema({
TITLE: 'string',
ARTIST: 'string',
COUNTRY: 'string',
COMPANY: 'string',
PRICE: 'string',
YEAR: 'string'

// Create model
var Cd = mongoose.model('Cd', CdSchema);

// Remove all old records from the collections
Cd.remove({}, function() {
console.log("Removed all previous records in Collection")

// Read file and store data into db
fs.readFile('./json-files/cd_catalog.json', 'utf8', function (err,data) {
data = JSON.parse(data);

for(var i = 0; i < data.CATALOG.CD.length; i++) {
  var newCD = new Cd();
  newCD.YEAR = data.CATALOG.CD[i].YEAR; (err) {});
console.log("Data saved to db");


Where should I add command mongoose.disconnect(); if I place it in the end, the data is not stored...