Created
April 26, 2020 14:35
-
-
Save obengwilliam/d202c7325c210f6fe182503e0bd5a4af to your computer and use it in GitHub Desktop.
quickly connect to mongodb using mongoose #mongoose #mongodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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