1const mongoose = require('mongoose');
2mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});
3
4const Cat = mongoose.model('Cat', { name: String });
5
6const kitty = new Cat({ name: 'Zildjian' });
7kitty.save().then(() => console.log('meow'));
1await mongoose.connect('mongodb://localhost/my_database', { useNewUrlParser: true, useUnifiedTopology: true});
1// getting-started.js
2var mongoose = require('mongoose');
3mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true});
4var db = mongoose.connection;
5db.on('error', console.error.bind(console, 'connection error:'));
6db.once('open', function() {
7 // we're connected!
8});
1const db = mongoose.connection;
2db.on('error', console.error.bind(console, 'connection error:'));
3db.once('open', function() {
4 // we're connected!
5});
1var db = mongoose.connection;
2db.on('error', console.error.bind(console, 'connection error:'));
3db.once('open', function() {
4 // we're connected!
5});