How to use the mongoose.mongo 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 muffin / server / utils / db.js View on Github external
info.message = 'Please make sure it\'s running and accessible!'
  }

  log('Couldn\'t connect to DB: ' + info.message)
  process.exit(1)
})

process.on('SIGINT', () => connection.close(() => {
  process.exit(0)
}))

export { connection as rope }
export { mongoose as goose }

// Tell gridfs where to find the files
grid.mongo = mongoose.mongo
const gridConnection = grid(connection.db)

export { gridConnection as fs }
github SciSpike / yaktor / bin / static / config / global / 02_mongo.js View on Github external
var logger = require('yaktor/logger')
logger.info(__filename)
var mongoose = require('mongoose')
var GridFs
try {
  GridFs = require('gridfs-stream')
  GridFs.mongo = mongoose.mongo
} catch (e) {
  logger.warn('gridfs not found, skipping.')
}
/* jshint eqnull:true */
module.exports = function (yaktor, done) {
  require('mongoose-pagination')
  var f1nU = mongoose.Model.findOneAndUpdate
  // Monkey Patch for update existing doc.
  mongoose.Model.findOneAndUpdate = function (q, doc) {
    if (doc != null && doc.toObject != null) {
      var newDoc = doc.toObject()
      delete newDoc._id
      arguments[1] = newDoc
      return f1nU.apply(this, arguments)
    } else {
      return f1nU.apply(this, arguments)
github michaelkrone / generator-material-app / generators / app / templates / server / api / user(auth) / user.params.js View on Github external
/**
 * Module for initializing the user api request parameters for 'api/user' routes.
 * Export the {@link user:Parameters~registerUserParams}
 * function to register the api routes on the passed express router.
 * Parameters registered:
 * 'id', attached as 'user' to the request object
 * @module {function} user:parameters
 * @requires {@link user:model}
 */
'use strict';

var User = require('./user.model').model;
var ObjectID = require('mongoose').mongo.BSONPure.ObjectID;

// export the function to register all user request params
module.exports = registerUserParams;

/**
 * Attach request parameters to the given router.
 * @param router {express.Router} - The router to attach the parameters to
 */
function registerUserParams(router) {
	router.param('id', registerIdParam);
	// add params below
}

/**
 * Register the default id parameter for 'api/user' requests.
 * Add a 'user' property to the current request which is the
github mongoosejs / mongoose-long / test / index.js View on Github external
it('extends mongoose.Types', function(){
    assert.ok(mongoose.Types.Long);
    assert.equal(mongoose.mongo.Long, mongoose.Types.Long);
  })
github devconcept / multer-gridfs-storage / test / storage.spec.js View on Github external
storage.on('connection', (_db) => {
        expect(_db).to.be.instanceOf(mongoose.mongo.Db);
        db = _db;
        client = mongoose.connection;

        request(app)
          .post('/mongoose_instance')
          .attach('photos', files[0])
          .attach('photos', files[1])
          .end((err) => {
            expect(err).to.equal(null);
            expect(result.files.length).to.equal(2);
            done(err);
          });
      });
    });
github vivekratnavel / omniboard / server / config / database.js View on Github external
db.once('open', function() {
    console.log(`Connection to ${mongodbURI} established successfully!`);
    gfs = Grid(db.db, mongoose.mongo);
  });
github YourTradingSystems / EasyERP / server.js View on Github external
var http = require('http'),
    url = require('url'),
    fs = require("fs");


var mongoose = require('mongoose');
var Admin = mongoose.mongo.Admin;
var dbsArray = [];
var dbsNames = [];
//Event Listener in Server and Triggering Events
var events = require('events');
var event = new events.EventEmitter();

var mainDb = mongoose.createConnection('localhost', 'mainDB');

mainDb.on('error', console.error.bind(console, 'connection error:'));
mainDb.once('open', function callback() {
    console.log("Connection to mainDB is success");
    var mainDBSchema = mongoose.Schema({
        _id: Number,
        url: { type: String, default: 'localhost' },
        DBname: { type: String, default: '' },
        pass: { type: String, default: '' },
github cliffmoney / jabbr / server / api / recording / sendRecording.js View on Github external
var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    conn = mongoose.connection,
    url = require("url"),
    path = require("path"),
    fs = require('fs'),
    Grid = require('gridfs-stream');
    Grid.mongo = mongoose.mongo;


    module.exports = function(userId, cb){
      var gfs = Grid(conn.db);
      var streams = [];
      gfs.files.find({ metadata: {userId: userId} }).toArray(function (err, files) {
          if (err) {
               throw (err);
          }
          files.forEach(function (file){
            var readStream = gfs.createReadStream({
               filename: file.filename
            });
            streams.push(readStream);
          });
          cb(streams);
github tomgrek / hackathon-skeleton / server / server.js View on Github external
passport.deserializeUser(function(id, done) {
      User.findById(mongoose.mongo.ObjectId(id), function(err, user) {
        done(null, user);
      });
    });
    passport.use(new LocalStrategy(function(username, password, done) {