How to use the mongoose.Promise 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 backstrokeapp / server / test / setup.js View on Github external
// Setup code that should run before all tests.


// Give mongoose a promise implementation.
import Promise from 'bluebird';
import mongoose from 'mongoose';
mongoose.Promise = Promise;

// make mixpanel null
global.mixpanel = {
  track() { return null; },
  identify() { return null; },
};
github EQuimper / nodejs-api-boilerplate / src / config / database.js View on Github external
/* eslint-disable no-console */

/**
 * Configuration for the database
 */

import mongoose from 'mongoose';

import constants from './constants';

// Remove the warning with Promise
mongoose.Promise = global.Promise;

// If debug run the mongoose debug options
mongoose.set('debug', process.env.MONGOOSE_DEBUG);

// Connect the db with the url provide
try {
  mongoose.connect(constants.MONGO_URL);
} catch (err) {
  mongoose.createConnection(constants.MONGO_URL);
}

mongoose.connection
  .once('open', () => console.log('MongoDB Running'))
  .on('error', e => {
    throw e;
  });
github shamahoque / mern-marketplace / server / server.js View on Github external
import config from './../config/config'
import app from './express'
import mongoose from 'mongoose'

// Connection URL
mongoose.Promise = global.Promise
mongoose.connect(config.mongoUri)
mongoose.connection.on('error', () => {
  throw new Error(`unable to connect to database: ${mongoUri}`)
})

app.listen(config.port, (err) => {
  if (err) {
    console.log(err)
  }
  console.info('Server started on port %s.', config.port)
})
github TobiahRex / reactBoilerplate / server / server.js View on Github external
/* eslint-disable import/newline-after-import, import/imports-first*/
require('dotenv').config({ silent: true });

import express from 'express';
import path from 'path';
import morgan from 'morgan';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import webpack from 'webpack';
import hotMiddleware from 'webpack-hot-middleware';
import devMiddleware from 'webpack-dev-middleware';
import webpackConfig from '../webpack.config';
import api from './api';

mongoose.Promise = Promise;
const PORT = process.env.PORT || 3000;
const MONGO = process.env.MONGODB_URI || 'mongodb://localhost/reactBoilerplate';
const app = express();
const compiler = webpack(webpackConfig);
app.use(devMiddleware(compiler, {
  publicPath: webpackConfig.output.publicPath,
  noInfo: true,
  quiet: false,
  stats: {
    assets: true,
    colors: true,
    version: true,
    hash: true,
    timings: false,
    chunks: false,
    chunkModules: false,
github bitrecipe / mern-minimal / src / server / index.js View on Github external
import compression from "compression";
import App from "./../client/App.js";
import { configureStore } from './../client/store.js';
import createRoutes from "./../client/routes.js";
import { ChunkExtractor } from '@loadable/server';
import mongoose from 'mongoose';
import axios from "axios";
import serverConfig from "./config.js";
import csrf from "csurf";
import serialize from 'serialize-javascript';
import morgan from 'morgan';
import logger from './middlewares/logger.js';
import authRoutes from './routes/auth.js';
import commonRoutes from './routes/common.js';

mongoose.Promise = global.Promise;

mongoose.connect(serverConfig.mongodb.url, serverConfig.mongodb.options, function (err) {
    if (!err) {
        logger.info("mongodb connected to " + serverConfig.mongodb.url);
        require('./utils/initDB.js');
    } else {
        logger.error(err);
        process.exit(1);
    }
});

const app = express();

app.use(morgan('short', { "stream": logger.stream }));

app.use(compression());
github codevet / daipay / src / server / connector.js View on Github external
import mongoose from 'mongoose'

var conn

if (!conn) {
  process.on('unhandledRejection', function(reason, promise) {
    console.log(promise);
  });
  const url = process.env.MONGO_URL || (typeof __TEST__ != 'undefined' && __TEST__ ? 'mongodb://localhost/daipay_test' : 'mongodb://localhost/daipay')
  console.log(`connecting to ${url}`)
  mongoose.connect(url, { useNewUrlParser: true })
  mongoose.Promise = global.Promise
  conn = mongoose
}

export default conn
github Remchi / bookworm-api / src / index.js View on Github external
import express from "express";
import path from "path";
import mongoose from "mongoose";
import bodyParser from "body-parser";
import dotenv from "dotenv";
import Promise from "bluebird";

import auth from "./routes/auth";
import users from "./routes/users";
import books from "./routes/books";

dotenv.config();
const app = express();
app.use(bodyParser.json());
mongoose.Promise = Promise;
mongoose.connect(process.env.MONGODB_URL, { useMongoClient: true });

app.use("/api/auth", auth);
app.use("/api/users", users);
app.use("/api/books", books);

app.get("/*", (req, res) => {
  res.sendFile(path.join(__dirname, "index.html"));
});

app.listen(8080, () => console.log("Running on localhost:8080"));
github StephenGrider / UpStarMusic / src / main.js View on Github external
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import ReduxThunk from 'redux-thunk';
import { Db, Server } from 'mongodb';
import reducers from './reducers';
import Routes from './router';
import mongoose from 'mongoose';
import './seeds';

mongoose.Promise = Promise;

const App = () => {
  const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));

  return (
    
      
    
  );
};

const db = new Db('upstar_music', new Server('localhost', 27017));
db.open()
  .then(() => {
    window.db = db;
    mongoose.connect('mongodb://localhost/upstar_music');
github ecmadao / hacknical / app / models / mongoose / index.js View on Github external
if (err) {
    logger.error('connect to %s error: ', mongodbUrl, err.message);
  }
}

if (process.env.NODE_ENV === 'production') {
  mongoose.connect(mongodbUrl, {
    useMongoClient: true
  }, handleErr);
} else {
  mongoose.connect(mongodbUrl, {
    useMongoClient: true
  }, handleErr);
}

mongoose.Promise = global.Promise;

export default mongoose;