Skip to content

Instantly share code, notes, and snippets.

@Bilguun132
Created February 23, 2019 19:39
Show Gist options
  • Select an option

  • Save Bilguun132/dcf530e887f9bc4349f4b42a6a4dbeee to your computer and use it in GitHub Desktop.

Select an option

Save Bilguun132/dcf530e887f9bc4349f4b42a6a4dbeee to your computer and use it in GitHub Desktop.
MongoDemo-Tutorial-createObjectWithValidateErrors
async function createValidate() {
const avengersMovie = new Movie({
director: 'Joss Whedon',
genre: [], //NoSQL Db -> Document can be complex object unlike MySQL
price: 10
});
try {
await avengersMovie.save()
console.log(avengersMovie);
}
catch(ex){
for (field in ex.errors){
console.log(ex.errors[field].message);
}
}
}
createValidate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment