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

[Docs] Populate's behavior is not greatly documented #12111

Closed
2 tasks done
hasezoey opened this issue Jul 15, 2022 · 0 comments
Closed
2 tasks done

[Docs] Populate's behavior is not greatly documented #12111

hasezoey opened this issue Jul 15, 2022 · 0 comments
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@hasezoey
Copy link
Collaborator

Prerequisites

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

Issue

Currently populate's behavior is not greatly documented for cases in which it fails, the documentation currently just says not populated, which could mean many things, so this issue proposes that the documentation would need to be updated.

Current docs:

mongoose/lib/document.js

Lines 4181 to 4200 in 115f922

/**
* Populates paths on an existing document.
*
* #### Example:
*
* await doc.populate([
* 'stories',
* { path: 'fans', sort: { name: -1 } }
* ]);
* doc.populated('stories'); // Array of ObjectIds
* doc.stories[0].title; // 'Casino Royale'
* doc.populated('fans'); // Array of ObjectIds
*
* await doc.populate('fans', '-email');
* doc.fans[0].email // not populated
*
* await doc.populate('author fans', '-email');
* doc.author.email // not populated
* doc.fans[0].email // not populated
*

Things that should be changed / documented:

  • change not populated to actually say what type is expected in case it fails (like is it null | undefined, or the raw id)
  • what happens for paths that dont actually exist (does populate throw or try to do it anyway or just ignore it)
  • document what the actual return type of .populate call is (currently it is just Promise)
  • document that Document.prototype.populate is (at least a bit) different from Query.prototype.populate

PS: some of those may be fixed by just using the @see tags from the jsdoc in the documentation

@IslandRhythms IslandRhythms added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Jul 18, 2022
@vkarpov15 vkarpov15 added this to the 6.4.7 milestone Jul 18, 2022
@vkarpov15 vkarpov15 modified the milestones: 6.4.7, 6.4.9 Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests

3 participants