question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model.create(doc, fn) should save all valid documents.

See original GitHub issue

I’m trying to save a set of documents using Model.create(documents, function(error){...}) I found when a document is invalid, the previous documents were saved but the following will never be saved.

I think Model.create should save all valid documents. I would like an API like this.

//Passing one doc
Person.create({name: "John"}, function(error, john){...})

//Passing an array
var persons = [{name: "John"}, {name: "Doe"}];
Person.create(persons, function(errors, docs){...});

//Passing individual docs
Person.create({name: "John"}, {name: "Doe"}, function(errors, docs){...});

I would like to do a pull request, but first I want to know what do you think.

Issue Analytics

  • State:open
  • Created 10 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

1reaction
lineuscommented, Oct 12, 2018

sounds good to me. I’ll take a stab at it.

0reactions
vkarpov15commented, Oct 11, 2018

@lineus we could just add a list of saved docs and a list of docs that failed to save in the error. Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving multiple documents with Mongoose and doing ...
When the last document is saved, I want to report (i.e. send an event) that all documents have been saved. The way I'm...
Read more >
Mongoose v6.8.1: Model
Shortcut for saving one or more documents to the database. MyModel.create(docs) does new MyModel(doc).save() for every doc in docs. This function triggers the ......
Read more >
An Introduction to Mongoose's `save()` Function - Mastering JS
When you create an instance of a Mongoose model using new , calling save() makes Mongoose insert a new document. const Person =...
Read more >
Model Querying - Basics - Sequelize
Simple INSERT queries​ ... const jane = await User.create({ firstName: "Jane", lastName: "Doe" }); console.log("Jane's auto-generated ID:", jane.
Read more >
wither::model::Model - Rust - Docs.rs
API documentation for the Rust `Model` trait in crate `wither`. ... fn save(&mut self, db: Database, filter: Option<Document>) -> Result<()> { ... }....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found