Skip to content

Instantly share code, notes, and snippets.

@obengwilliam
Created April 26, 2020 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obengwilliam/d202c7325c210f6fe182503e0bd5a4af to your computer and use it in GitHub Desktop.
Save obengwilliam/d202c7325c210f6fe182503e0bd5a4af to your computer and use it in GitHub Desktop.
quickly connect to mongodb using mongoose #mongoose #mongodb
'use strict';
const mongoose = require('mongoose');
run().catch(err => console.log(err));
async function run() {
mongoose.set('useUnifiedTopology', true);
mongoose.set('useNewUrlParser', true);
await mongoose.connect('mongodb://localhost:27017/test');
const Model = mongoose.model('Test', new mongoose.Schema({ name: String }));
await Model.findOne();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment