Skip to content
New issue

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

Model.bulkWrite weird behaviour #13597

Closed
1 task done
wisdomabioye opened this issue Jul 10, 2023 · 2 comments
Closed
1 task done

Model.bulkWrite weird behaviour #13597

wisdomabioye opened this issue Jul 10, 2023 · 2 comments
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.

Comments

@wisdomabioye
Copy link

Prerequisites

  • I have written a descriptive issue title

Mongoose version

7.3.0

Node.js version

18.15.0

MongoDB version

6.0.6

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

22.04.2

Issue

Consider this code snippet

async function performBulkWrite(operations) {
  // ...
  console.log('before write');
  await Model.bulkWrite(operations);
  console.log('after write'); // this line never logged if operations.length === 0
  // ...
}

This code never reach here console.log('after write'); if operations.length === 0;

Is this the right behaviour?

I have fixed it using if (operations.length === 0) { ... } but I'm still curious.

@wisdomabioye wisdomabioye added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Jul 10, 2023
@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Jul 12, 2023
@vkarpov15 vkarpov15 added this to the 7.4.1 milestone Jul 12, 2023
@IslandRhythms IslandRhythms added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Jul 14, 2023
@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({ 
  name: String
});

const Test = mongoose.model('Test', testSchema);

async function run() {
  await mongoose.connect('mongodb://localhost:27017');
  await mongoose.connection.dropDatabase();

  const array = [];

  await Test.bulkWrite(array);
  console.log('done');
}

run();

@vkarpov15 vkarpov15 removed this from the 7.4.1 milestone Jul 18, 2023
@JavaScriptBach
Copy link
Contributor

I found a similar issue and provided a repro. See #13664

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
Projects
None yet
Development

No branches or pull requests

4 participants