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

doc.isModified returns false whenever multiple fields are specified #13667

Closed
2 tasks done
ThoseGrapefruits opened this issue Jul 27, 2023 · 2 comments
Closed
2 tasks done
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@ThoseGrapefruits
Copy link

ThoseGrapefruits commented Jul 27, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.11.4, 7.4.1

Node.js version

20.5.0

MongoDB server version

6.0.2

Typescript version (if applicable)

No response

Description

Hello!

It seems like isModified had a regression somewhat recently and is now returning false whenever multiple paths are passed, even if one of those paths was modified. Not sure if I'm doing something wrong, but I was able to reproduce it on a fresh install of latest mongoose in an isolated repro script. I tested on the latest versions of 6.x and 7.x and the results are the same. I am upgrading from 6.9.0, where this repro script works as expected.

As far as I can tell in the documentation, this is still a supported feature.

Thanks for your time,
Logan

Steps to Reproduce

const mongoose = require('mongoose');

const Cat = mongoose.model('Cat', {
  name: String, 
  type: String
});

async function run() {
  await mongoose.connect('mongodb://localhost:27017/cats', {
    useNewUrlParser: true, useUnifiedTopology: true});

  await mongoose.connection.dropDatabase();

  const myCat = new Cat({ name: 'Lord Fluffles' })
  await myCat.save();

  myCat.name = 'Captain Fluffles';

  console.log('isModified multiple', myCat.isModified('name type'));
  console.log('isModified single', myCat.isModified('name'));
  console.log('isDirectModified', myCat.isDirectModified('name type'));
}

run().then(() => process.exit(0));

Expected Behavior

The repro script should print true on every line, but the isModified multiple line prints false.

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jul 28, 2023
@vkarpov15 vkarpov15 added this to the 7.4.2 milestone Aug 1, 2023
@vkarpov15
Copy link
Collaborator

Fixed by #13674

@k-chop
Copy link
Contributor

k-chop commented Oct 6, 2023

@vkarpov15 I also encountered this issue when I updated to 6.12.0.
Would it be possible for this fix to be backported to 6.x?

I've already fixed our app by passing array instead of string, but it would be nice if this is fixed in 6.x.
I opened backport PR: #13940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

4 participants