Reputation: 23
there I am getting this error while trying to insert an array into my mongo database using mongoose. code:
mongoose.connect("mongodb://localhost:27017/todoList", {
useNewUrlParser: true,
});
const itemsSchema = mongoose.Schema({
task: String,
});
const Items = mongoose.model("item", itemsSchema);
const item1 = new Items({
task: "Welcome to your todo-list",
});
const item2 = new Items({
task: "Hit the + button to add new task",
});
const item3 = new Items({
task: "<-- button to delete the item",
});
const defaultItems = [item1, item3, item3];
Items.insertMany(defaultItems, (err) => {
if (err) {
console.log(err);
} else {
console.log("Default Items inserted succesfully. ");
}
});
the error : ParallelValidateError: Can't validate() the same doc multiple times in parallel.
Upvotes: 0
Views: 723
Reputation: 11
const defaultItems = [item1, item3, item3];
I had the same problem, the issue was adding 2 of the same items in the array.
Upvotes: 1
Reputation: 28
There is very common mistake in your code that is when you are making an array of your items there is the mistake that you are adding your Item3 two times that's why terminal is giving you error that Can't validate() the same doc multiple times in parallel.
This error is only because that you are trying to adding your data two times
Upvotes: 1