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

Improve docs on post find hooks #9982

Closed
tom-thorne opened this issue Mar 1, 2021 · 2 comments · Fixed by #10015
Closed

Improve docs on post find hooks #9982

tom-thorne opened this issue Mar 1, 2021 · 2 comments · Fixed by #10015
Assignees
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@tom-thorne
Copy link

Using mongoose 5.18.11
Do you want to request a feature or report a bug?
Documentation Bug

The callback type on schema hook for post 'find' is unclear. I had assumed it was an array, but now after commit
4dad667 it is also a doc.

// what type is arg - is it an array or a doc ?
Schema.post('find', (arg: any) => {
  ...
});

It would be super helpful if the documentation made it clearer what the types used in hooks should be.

@IslandRhythms IslandRhythms added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Mar 2, 2021
@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 docs This issue is due to a mistake or omission in the mongoosejs.com documentation labels Mar 8, 2021
@vkarpov15 vkarpov15 added this to the 5.11.20 milestone Mar 8, 2021
@vkarpov15
Copy link
Collaborator

@tom-thorne arg should always be an array. We'll see if we can repro the case where it is a doc.

@IslandRhythms IslandRhythms self-assigned this Mar 8, 2021
@vkarpov15 vkarpov15 removed their assignment Mar 10, 2021
@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');

const run = async () => {
    await mongoose.connect('mongodb://localhost:27017/test', {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });
    await mongoose.connection.dropDatabase();
const testSchema = new mongoose.Schema({name: String});
    testSchema.post('find', (result) => {
        console.log('Hello', result);
    });
    const Test = mongoose.model('Test', testSchema);
    await Test.create({name: 'Daniel'},{name: 'Val'}, {name: 'Daniel'});
    const query = await Test.find({name: 'Daniel'}).cursor();
    query.next().then(doc => {
        console.log('doc', doc);
    });

}
run().catch(err => console.log(err));

@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Mar 10, 2021
@vkarpov15 vkarpov15 modified the milestones: 5.11.20, 5.12.1 Mar 11, 2021
@vkarpov15 vkarpov15 modified the milestones: 5.12.1, 5.12.2 Mar 18, 2021
vkarpov15 added a commit that referenced this issue Mar 19, 2021
fix? hooks now return an array only and typescript bugs fixed?
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

Successfully merging a pull request may close this issue.

3 participants