mongoose in node.js 1

mongoose in node.js

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});

const Cat = mongoose.model('Cat', { name: String });

const kitty = new Cat({ name: 'Zildjian' }); => console.log('meow'));

Here is what the above code is Doing:
1. We’re importing the mongoose module.
2. We’re connecting to a test database on our locally running instance of MongoDB.
3. We’re creating a Cat model.
4. We’re creating a new instance of Cat.
5. We’re saving the new cat instance, and logging the value of the _id property.

Similar Posts