How to use the mongoose.createConnection function in mongoose

To help you get started, we’ve selected a few mongoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EasyERP / EasyERP_open_source / updateCollections / Done / updateCustomers.js View on Github external
var mongoose = require('mongoose');
var async = require('async');
var isoWeekYearComposer = require('../../helpers/isoWeekYearComposer');
require('../../models/index.js');
var connectOptions = {
    user: 'easyErp',
    pass: '1q2w3e!@#',
    w   : 1,
    j   : true
};

// var dbObject = mongoose.createConnection('144.76.56.111', 'sergey', 28017, connectOptions);
var dbObject = mongoose.createConnection('erp.thinkmobiles.com', 'production', 27017, connectOptions);

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

dbObject.once('open', function callback() {
    var customerSchema;
    var Customer;

    console.log("Connection to db is success");

    customerSchema = mongoose.Schemas.Customer;

    Customer = dbObject.model('Customer', customerSchema);
    Customer.update({}, {$set : {isHidden : false}}, {multi : true},
    function (err, res){
        if (err){
            console.log(err);
github EasyERP / EasyERP_open_source / updateCollections / Done / renameSales.js View on Github external
/**
 * Created by liliy on 13.06.2016.
 */
var mongoose = require('mongoose');
require('../../models/index.js');
var ModuleSchema = mongoose.Schemas.modules;

var connectOptions = {
    user: 'easyErp',
    pass: '1q2w3e!@#',
    w   : 1,
    j   : true
};

// var dbObject = mongoose.createConnection('144.76.56.111', 'pavlodb', 28017, connectOptions);
var dbObject = mongoose.createConnection('erp.thinkmobiles.com', 'production', 27017, connectOptions);

var Module = dbObject.model("modules", ModuleSchema);

Module.update({href: 'Sales'}, {mname: "CRM"}, function (err) {
    if (err) {
        console.log(err);
    }
    console.log('Good');
});
github inbloom / secure-data-service / tools / jobReport / server / server.js View on Github external
function createConnection(host) {
  var uri = 'mongodb://' + host + '/ingestion_batch_job';

  var con = mongoose.createConnection(uri);

  // define _id in Schema otherwise mongoose does not return it
  var schema = new mongoose.Schema({
    _id: String,
    notes : { comments: String, errorSummary: String, environment: String, isSharded: String, isPreSplit: String, 
      isBalancerOn: String, isClustered: String, codeTag: String}
  });

  // create model object for newBatchJob
  // Mongoose#model(name, [schema], [collection], [skipInit])
  var Error = con.model('Error', schema, 'error'); 
  var NewBatchJob = con.model('NewBatchJob', schema, 'newBatchJob');
  var BatchJobStage = con.model('BatchJobStage', schema, 'batchJobStage');
  var StagedEntities = con.model('StagedEntities', schema, 'stagedEntities');
  var TenantJobLock = con.model('TenantJobLock', schema, 'tenantJobLock');
github LeadingEdgeForum / atlas2 / tests / server / walkthrough4_tests.js View on Github external
before(function(done) {
    mongooseConnection = mongoose.createConnection(getTestDB('walkthrough4_tests'));
    mongooseConnection.on('error', console.error.bind(console, 'connection error:'));
    mongooseConnection.once('open', function callback() {
      WardleyMap = require('../../src-server/workspace/model/map-schema')(mongooseConnection);
      Workspace = require('../../src-server/workspace/model/workspace-schema')(mongooseConnection);
      Node = require('../../src-server/workspace/model/node-schema')(mongooseConnection);
      return Workspace
            .initWorkspace("name2", "description2", "purpose2", owner)
            .then(function(workspace) {
              currentWorkspace = workspace;
              return workspace.createAMap({
                name: 'map name ' + 0,
                description: 'description' + 0,
                purpose: 'purpose' + 0,
                owner: owner
              })
              .then(function(createdMap){
github EasyERP / EasyERP_open_source / updateCollections / Done / updateLeadsPersonCompany.js View on Github external
var mongoose = require('mongoose');
var async = require('async');
var isoWeekYearComposer = require('../../helpers/isoWeekYearComposer');
require('../../models/index.js');
var connectOptions = {
    user: 'easyerp',
    pass: '1q2w3e!@#',
    w   : 1,
    j   : true
};

//var dbObject = mongoose.createConnection('144.76.56.111', 'sergey', 28017, connectOptions);
var dbObject = mongoose.createConnection('erp.thinkmobiles.com', 'production'/*, 27017, connectOptions*/);

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

dbObject.once('open', function callback() {
    var opportunitySchema;
    var customerSchema;
    var Customer;
    var Opportunitie;

    console.log("Connection to db is success");

    opportunitySchema = mongoose.Schemas.Opportunitie;
    customerSchema = mongoose.Schemas.Customer;
    Opportunitie = dbObject.model('Opportunities', opportunitySchema);
    Customer = dbObject.model('Customer', customerSchema);
github EasyERP / EasyERP_open_source / updateCollections / Done / replaceProjectTypes.js View on Github external
var mongoose = require('mongoose');
require('../../models/index.js');

var projectTypeSchema = mongoose.Schemas['projectType'];

var connectOptions = {
    user: 'easyErp',
    pass: '1q2w3e!@#',
    w   : 1,
    j   : true
};
var dbObject = mongoose.createConnection('localhost', 'production', 27017, connectOptions);

dbObject.on('error', console.error.bind(console, 'connection error:'));
dbObject.once('open', function callback() {
    console.log("Connection to production is success");
});

var ProjectTypes = dbObject.model("projectType", projectTypeSchema);

var newProjectTypes = [
    {
        _id : 'fixed',
        name: 'fixed'
    }, {
        _id : 'time & material',
        name: 'time & material'
    }, {
github jedireza / drywall / app.js View on Github external
passport = require('passport'),
    mongoose = require('mongoose'),
    helmet = require('helmet'),
    csrf = require('csurf');

//create express app
var app = express();

//keep reference to config
app.config = config;

//setup the web server
app.server = http.createServer(app);

//setup mongoose
app.db = mongoose.createConnection(config.mongodb.uri);
app.db.on('error', console.error.bind(console, 'mongoose connection error: '));
app.db.once('open', function () {
  //and... we have a data store
});

//config data models
require('./models')(app, mongoose);

//settings
app.disable('x-powered-by');
app.set('port', config.port);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

//middleware
app.use(require('morgan')('dev'));
github EasyERP / EasyERP_open_source / updateCollections / Done / updateJobsTypes.js View on Github external
/**
 * Created by lilya on 23/11/15.
 */
var mongoose = require('mongoose');
require('../models/index.js');
var _ = require('../node_modules/underscore');
var async = require('async');
var JobsSchema = mongoose.Schemas['jobs'];

var dbObject = mongoose.createConnection('localhost', 'production');
dbObject.on('error', console.error.bind(console, 'connection error:'));
dbObject.once('open', function callback() {
    console.log("Connection to production is success");

    var Job = dbObject.model("jobs", JobsSchema);
    var updateObj = {};
    var jobId;
    var count = 0;

    var query = Job.find().lean();

    query.exec(function (err, result) {
        if (err) {
            return console.log(err);
        }
github EasyERP / EasyERP_open_source / services / session.js View on Github external
if (typeof options === 'function') {
                callback = options;
                options = {};
            }

            if (typeof callback !== 'function') {
                callback = function () {
                };
            }

            if (options) {
                _options = _.assign(_options, options);
            }

            connection = mongoose.createConnection(process.env.MAIN_DB_HOST, process.env.MAIN_DB_NAME, process.env.DB_PORT, {
                db    : {native_parser: true},
                server: {poolSize: 1},
                user  : process.env.DB_USER,
                pass  : process.env.DB_PASS
            });

            connection.on('error', function (err) {
                err = err || 'connection error';

                if (typeof callback === 'function') {
                    callback(err);
                }
            });
            connection.once('open', function () {
                db = connection.db;
                db.collection('sessions', function (err, collection) {
github oohnoitz / jii / lib / db / mongodb.js View on Github external
import mongoose from 'mongoose'
import config from '../../config'

const debug = require('debug')('jii::mongodb')
const settings = { server: { auto_reconnect: true } }
const client = mongoose.createConnection(`mongodb://${config.db.host}:${config.db.port}/${config.db.data}`, settings)

client.on('open', function (err) {
  if (err) {
    debug(err)
  } else {
    debug(`connected to database :: ${config.db.data}`);
  }
});

export default client