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

Hydrate populated fields not mark them as populated in the document #15048

Closed
2 tasks done
yamaha252 opened this issue Nov 20, 2024 · 0 comments · Fixed by #15080
Closed
2 tasks done

Hydrate populated fields not mark them as populated in the document #15048

yamaha252 opened this issue Nov 20, 2024 · 0 comments · Fixed by #15080
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Milestone

Comments

@yamaha252
Copy link

yamaha252 commented Nov 20, 2024

Prerequisites

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

Mongoose version

8.8.2

Node.js version

20.7.0

MongoDB server version

5.0.2

Typescript version (if applicable)

5.6.3

Description

On hydrating a document with populated fields (hydratedPopulatedDocs: true), they doesn't pass document.populated(...) check.

Steps to Reproduce

const userSchema = new Schema({
  name: String
});
const companySchema = new Schema({
  name: String,
  users: [{ ref: 'User', type: Schema.Types.ObjectId }]
});

db.model('UserTestHydrate', userSchema);
const Company = db.model('CompanyTestHydrate', companySchema);

const users = [{ _id: new mongoose.Types.ObjectId(), name: 'Val' }];
const company = { _id: new mongoose.Types.ObjectId(), name: 'Booster', users: [users[0]] };

const C = Company.hydrate(company, null, { hydratedPopulatedDocs: true });
assert(C.populated('users')); // fails

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(C.populated('users'))

Expected Behavior

Hydrating populated fields should write population info in the document to make populated method works.

yamaha252 added a commit to yamaha252/mongoose that referenced this issue Nov 20, 2024
@yamaha252 yamaha252 changed the title Hydrate populated fields not mark them as populated in the model Hydrate populated fields not mark them as populated in the document Nov 20, 2024
yamaha252 added a commit to yamaha252/mongoose that referenced this issue Nov 25, 2024
yamaha252 added a commit to yamaha252/mongoose that referenced this issue Nov 25, 2024
yamaha252 added a commit to yamaha252/mongoose that referenced this issue Nov 26, 2024
yamaha252 added a commit to yamaha252/mongoose that referenced this issue Nov 26, 2024
@vkarpov15 vkarpov15 added this to the 8.8.4 milestone Nov 26, 2024
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Nov 26, 2024
vkarpov15 added a commit that referenced this issue Dec 5, 2024
@vkarpov15 vkarpov15 modified the milestones: 8.8.4, 8.9.1 Dec 5, 2024
vkarpov15 added a commit that referenced this issue Dec 11, 2024
fix: mark documents that are populated using hydratedPopulatedDocs option as populated in top-level doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Projects
None yet
2 participants