How to use the mongoose.Mongoose 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 lskjs / lskjs / packages / db / src / server.js View on Github external
export default async (ctx, params = {}) => {
  const { options = {}, uri, debug } = params;
  const defaultOptions = {
    keepAlive: true,
    useUnifiedTopology: true,
    useNewUrlParser: true,
    // autoReconnect: true,
    // reconnectTries: __DEV__ ? 10000 : 30,
    // reconnectInterval: __DEV__ ? 30000 : 1000,
    connectTimeoutMS: 5000,
    // sets the delay between every retry (milliseconds)
  };
  // console.log('options', options);
  // ctx.log.trace('db.init');
  const mongoose = new mongooseLib.Mongoose();
  mongoose.Promise = Promise;

  mongoose.run = () => {
    if (!uri) throw '!db.uri';
    const finalOptions = {
      ...defaultOptions,
      ...options,
    };
    const dbname = (uri || '').split('@')[1];
    ctx.log.trace('db.connect()', dbname); // finalOptions
    return new Promise((resolve, reject) => (
      mongoose.connect(uri, finalOptions).then(resolve, reject)
    ));
    // return mongoose.connect(uri, finalOptions); // , options
    // return mongoose;
  };
github strapi / strapi / test / start.js View on Github external
.map(db => new Promise((resolve, reject) => {
          const instance = new Mongoose();
          console.log(`mongodb://localhost/${db.name}`);
          instance.connect(`mongodb://localhost/${db.name}`, (err) => {
            if (err) {
              return reject(err);
            }

            instance.connection.db.dropDatabase();

            resolve();
          });
        }));
github Mockgoose / Mockgoose / test / options / Limit.spec.js View on Github external
describe('Mockgoose Limit Tests', function () {
    'use strict';

    var async = require('async');
    var mockgoose = require('./../../Mockgoose');
    var Mongoose = require('mongoose').Mongoose;
    var mongoose = new Mongoose();
    mockgoose(mongoose);
    mongoose.connect('mongodb://localhost/TestingDB');
    var SimpleModel = require('./../models/SimpleModel')(mongoose);


    beforeEach(function (done) {
        mockgoose.reset();
        async.times(10, function (n, next) {
            var model = new SimpleModel({
                name: n
            });
            model.save(next);
        }, done);
    });

    afterAll(function (done) {
github Mockgoose / Mockgoose / test / operations / logical / NorOperation.spec.js View on Github external
describe('Mockgoose $nor Tests', function () {
    'use strict';

    var mockgoose = require('./../../../Mockgoose');
    var Mongoose = require('mongoose').Mongoose;
    var mongoose = new Mongoose();
    mockgoose(mongoose);
    mongoose.connect('mongodb://localhost/TestingDB');

    var Schema = new mongoose.Schema({
        price: Number,
        qty: Number,
        sale: Boolean,
        carrier: {
            state: String
        }
    });
    var Model = mongoose.model('OrTests', Schema);

    beforeEach(function (done) {
        mockgoose.reset();
        Model.create(
github Mockgoose / Mockgoose / test / NestedReferences.spec.js View on Github external
describe('Nested Ref Tests', function () {
    'use strict';

    var mockgoose = require('../Mockgoose');
    var Mongoose = require('mongoose').Mongoose;
    var mongoose = new Mongoose();
    mockgoose(mongoose);
    mongoose.connect('mongodb://localhost:27017/TestingDB3');
    var ObjectId = mongoose.Schema.Types.ObjectId;

    var schema = new mongoose.Schema({
        values: [String],
        nestedValues: [
            { value: String}
        ],
        refs: [
            { type: ObjectId, ref: 'Ref' }
        ],
        nestedRefs: [
            { _ref: { type: ObjectId, ref: 'Ref' } }
        ]
    });
github Mockgoose / Mockgoose / test / operations / ElemMatchOperation.spec.js View on Github external
describe('Mockgoose $elemMatch Tests', function () {
    'use strict';

    var mockgoose = require('./../../Mockgoose');
    var Mongoose = require('mongoose').Mongoose;
    var mongoose = new Mongoose();
    mockgoose(mongoose);
    mongoose.connect('mongodb://localhost/TestingDB');

    var Schema = new mongoose.Schema({
        _id: Number,
        zipcode: Number,
        students: [
            {
                name: String,
                school: Number,
                age: Number
            }
        ]
    });
    var Model = mongoose.model('AllTests', Schema);
github Mockgoose / Mockgoose / test / use-cases.js View on Github external
beforeEach(function() {
        mongoose = new Mongoose();

        mockgoose(mongoose, FIXME_OPTIONS);
    });
github Mockgoose / Mockgoose / test / Remove.spec.js View on Github external
describe('Mockgoose Remove Tests', function () {
    'use strict';

    var mockgoose = require('../Mockgoose');
    var Mongoose = require('mongoose').Mongoose;
    var mongoose = new Mongoose();
    mockgoose(mongoose);
    mongoose.connect('mongodb://localhost/TestingDB');
    var AccountModel = require('./models/AccountModel')(mongoose);
    var SimpleModel = require('./models/SimpleModel')(mongoose);

    beforeEach(function (done) {
        mockgoose.reset();
        AccountModel.create(
            {email: 'valid@valid.com', password: 'password'},
            {email: 'invalid@invalid.com', password: 'password'},
            function (err, models) {
                expect(err).toBeFalsy();
                expect(models).toBeTruthy();
                SimpleModel.create(
                    {name: 'one', value: 'one'},
                    {name: 'one', value: 'two'},
github Mockgoose / Mockgoose / test / operations / comparison / LessThanOrEqualOperation.spec.js View on Github external
describe('Mockgoose $lte Tests', function () {
    'use strict';

    var mockgoose = require('./../../../Mockgoose');
    var Mongoose = require('mongoose').Mongoose;
    var mongoose = new Mongoose();
    mockgoose(mongoose);
    mongoose.connect('mongodb://localhost/TestingDB');

    var Schema = new mongoose.Schema({
        code: String,
        tags: [
            {type: String}
        ],
        qty: [
            {
                size: String,
                num: Number,
                color: String
            }
        ]
    });
github Mockgoose / Mockgoose / bugs / 192.js View on Github external
"use strict";

var expect = require('chai').expect;
var Mongoose = require('mongoose').Mongoose;
var mockgoose = require('../Mockgoose');
var mongoose = new Mongoose();
mockgoose(mongoose);

before(function(done) {
  console.log('inside before!');
  mongoose.connect('mongodb://localhost/mydb', function() {
      console.log('connected');
      done(); 
  });
});

describe('callback', function todoDescribe() {
  var modelSchema = new Schema({
      name: {
          type: Schema.Types.String,
          trim: true,
          select: true,