Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
};
.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();
});
}));
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) {
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(
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' } }
]
});
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);
beforeEach(function() {
mongoose = new Mongoose();
mockgoose(mongoose, FIXME_OPTIONS);
});
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'},
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
}
]
});
"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,