Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// make bluebird default Promise
Promise = require('bluebird'); // eslint-disable-line no-global-assign
// plugin bluebird promise in mongoose
mongoose.Promise = Promise;
// connect to mongo db
const mongoUri = config.mongo.host;
mongoose.connect(mongoUri, { server: { socketOptions: { keepAlive: 1 } } });
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${mongoUri}`);
});
// print mongoose logs in dev env
if (config.MONGOOSE_DEBUG) {
mongoose.set('debug', (collectionName, method, query, doc) => {
debug(`${collectionName}.${method}`, util.inspect(query, false, 20), doc);
});
}
// module.parent check is required to support mocha watch
// src: https://github.com/mochajs/mocha/issues/1912
if (!module.parent) {
// listen on port config.port
app.listen(config.port, () => {
console.info(`server started on port ${config.port} (${config.env})`); // eslint-disable-line no-console
});
}
export default app;
return new Promise((resolve, reject) => {
if (process.env.NODE_ENV !== 'production') {
mongoose.set('debug', true)
}
mongoose.connect(db)
mongoose.connection.on('disconnnected', () => {
maxConnectTimers++
if (maxConnectTimers < 5) {
mongoose.connect(db)
} else {
throw new Error('数据库挂了,赶快去修吧!!')
}
})
mongoose.connection.on('error', error => {
reject()
console.log(error)
})
mongoose.connection.on('open', () => {
import mongoose from 'mongoose'
import config from '../config'
mongoose.Promise = global.Promise
mongoose.set('debug',config.env === 'development')
export default mongoose.connect(config.mongodb.url,{
useMongoClient: true,
autoReconnect: true,
reconnectTries: 1800,
reconnectInterval: 2000
},function (err) {
if (err) {
console.log(err)
}
})
export {default as IllustsRecommendedNologin} from './illusts_recommended_nologin'
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect('mongodb://127.0.0.1/stackoverflow',
{
useMongoClient: true
}, function(err)
{
if (err)
console.log(err);
else
console.log('Connected to 127.0.0.1/stackoverflow');
});
mongoose.set('debug', true);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error: '));
var Badges = require('./app/models/BadgesSchema');
var Comments = require('./app/models/CommentsSchema');
var Posts = require('./app/models/PostsSchema');
var Votes = require('./app/models/VotesSchema');
var Users = require('./app/models/UsersSchema');
var Postlinks = require('./app/models/PostlinksSchema');
var Tags = require('./app/models/TagsSchema');
var err;
var badges = new Badges({});
err = badges.validateSync();
if (err !== undefined)
console.log(err);
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const constants = require('./config/constants');
//Connect to MongoDB
mongoose.Promise = global.Promise;
mongoose.set('debug', true);
mongoose.connect(
constants.mongoURI,
{
keepAlive: true,
reconnectTries: Number.MAX_VALUE,
useMongoClient: true,
},
);
require('./models/UrlShorten');
const app = express();
app.use(bodyParser.json());
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
import * as mongoose from 'mongoose';
import * as he from 'he';
import * as hljs from 'highlight.js';
import * as marked from 'marked';
import { chunk } from 'lodash';
import * as qs from 'querystring';
import * as url from 'url';
import { deleteFiles } from '../aws-s3';
import logger from '../logs';
import Discussion from './Discussion';
import Team from './Team';
mongoose.set('useFindAndModify', false);
function deletePostFiles(posts: IPostDocument[]) {
const imgRegEx = /\ {
let res = imgRegEx.exec(post.content);
while (res) {
const { bucket, path } = qs.parse(url.parse(res[1]).query);
if (typeof bucket !== 'string' || typeof path !== 'string') {
continue;
}
if (!files[bucket]) {
function connect() {
mongoose.set('debug', true);
return mongoose.connect(mongoUri, { useMongoClient: true });
}
import { uniq } from 'lodash';
import * as mongoose from 'mongoose';
import { generateNumberSlug } from '../utils/slugify';
import Post, { deletePostFiles } from './Post';
import Team from './Team';
mongoose.set('useFindAndModify', false);
const mongoSchema = new mongoose.Schema({
createdUserId: {
type: String,
required: true,
},
teamId: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
slug: {
type: String,
/*
* moleculer-db-adapter-mongoose
* Copyright (c) 2019 MoleculerJS (https://github.com/moleculerjs/moleculer-db)
* MIT Licensed
*/
"use strict";
const _ = require("lodash");
const Promise = require("bluebird");
const { ServiceSchemaError } = require("moleculer").Errors;
const mongoose = require("mongoose");
mongoose.set("useNewUrlParser", true);
mongoose.set("useFindAndModify", false);
mongoose.set("useCreateIndex", true);
class MongooseDbAdapter {
/**
* Creates an instance of MongooseDbAdapter.
* @param {String} uri
* @param {Object?} opts
*
* @memberof MongooseDbAdapter
*/
constructor(uri, opts) {
this.uri = uri,
this.opts = opts;
mongoose.Promise = Promise;
}