mongoose save a document

Solutions on MaxInterview for mongoose save a document by the best coders in the world

showing results for - "mongoose save a document"
Emanuele
17 Jun 2019
1const Person = mongoose.model('Person', Schema({
2  name: String,
3  rank: String
4}));
5
6const doc = new Person({
7  name: 'Will Riker',
8  rank: 'Commander'
9});
10// Inserts a new document with `name = 'Will Riker'` and
11// `rank = 'Commander'`
12await doc.save();
13
14const person = await Person.findOne();
15person.name; // 'Will Riker'