We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do you want to request a feature or report a bug?
A bug
What is the current behavior?
When an unmodified object is passed to bulkSave() an error is raised: TypeError: Cannot read property '0' of undefined
TypeError: Cannot read property '0' of undefined
If the current behavior is a bug, please provide the steps to reproduce.
const mongoose = require('mongoose') const { Schema } = mongoose const testSchema = new Schema({ name: { type: String, required: true, }, date: { type: Date, required: true, }, value: { type: Number, required: true, default: 0, }, }) new mongoose.model('Test', testSchema) const Test = mongoose.model('Test') async function bulkSave(data) { const bulk = [] for (const i in data) { const { name, date, value } = data[i] let test = await Test.findOne({ name: name, date: date }) if (!test) { test = new Test(data[i]) } test.value = value bulk.push(test) } return await Test.bulkSave(bulk) } async function run() { await mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true, }) await mongoose.connection.dropDatabase() const data1 = [ { name: 'Test 1', date: '2021-08-01T00:00:00.000Z', value: 10 }, { name: 'Test 1', date: '2021-08-02T00:00:00.000Z', value: 20 }, { name: 'Test 2', date: '2021-08-01T00:00:00.000Z', value: 15 }, ] await bulkSave(data1) const data2 = [ { name: 'Test 1', date: '2021-08-01T00:00:00.000Z', value: 15 }, { name: 'Test 1', date: '2021-08-02T00:00:00.000Z', value: 20 }, // <-- ERROR { name: 'Test 2', date: '2021-08-02T00:00:00.000Z', value: 25 }, ] await bulkSave(data2) console.log('Done') } run().catch((err) => console.log(err))
What is the expected behavior?
bulkSave() handle whether the document has changes or not.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node v13.11.0 Mongoose v5.13.2 MongoDB 4.2.5
The text was updated successfully, but these errors were encountered:
16b6a37
Merge pull request #10464 from AbdelrahmanHafez/gh-10437
0ff1c8a
test(model): assert Model.bulkSave(...) works if some document is not modified
No branches or pull requests
Do you want to request a feature or report a bug?
A bug
What is the current behavior?
When an unmodified object is passed to bulkSave() an error is raised:
TypeError: Cannot read property '0' of undefined
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
bulkSave() handle whether the document has changes or not.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node v13.11.0
Mongoose v5.13.2
MongoDB 4.2.5
The text was updated successfully, but these errors were encountered: