node mongoose insert db record code example

Example 1: node mongoose save document

// Example for a model called Person with two properties, e.g. name, surname
// Values to be saved
const person = { name: Jane, surname: Doe};
// you can access the _id property from savedPerson variable (savedPerson._id)
savedPerson = await new Person(person).save()

Example 2: mongoose add document

const Product = require('../models/product.js');

const product = new Product();
product.save()
		.then(doc => {})
        .catch(err => {});