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

findById(..).accessibleBy(..) returns an array instead of a document #87

Closed
wassgha opened this issue Jul 1, 2018 · 11 comments
Closed

Comments

@wassgha
Copy link

wassgha commented Jul 1, 2018

When accessibleBy is appended to a findById query, the resulting query is a single-object array instead of returning the object itself

@stalniy
Copy link
Owner

stalniy commented Jul 1, 2018

This is a bug. Just reverse the order of calls.

I will fix this tomorrow. Thanks for the issue!

@stalniy
Copy link
Owner

stalniy commented Jul 2, 2018

🎉 This issue has been resolved in version 2.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stalniy
Copy link
Owner

stalniy commented Jul 2, 2018

🎉 This issue has been resolved in version 0.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stalniy
Copy link
Owner

stalniy commented Jul 2, 2018

🎉 This issue has been resolved in version 2.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stalniy
Copy link
Owner

stalniy commented Jul 2, 2018

🎉 This issue has been resolved in version 0.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stalniy
Copy link
Owner

stalniy commented Jul 2, 2018

🎉 This issue has been resolved in version 0.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stalniy
Copy link
Owner

stalniy commented Jul 2, 2018

🎉 This issue has been resolved in version 0.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Alex0007
Copy link

Alex0007 commented Oct 16, 2022

@stalniy
findById is undefined after using accessibleBy.. Is this operator still supported?

console.log('find', ArticleModel.accessibleBy(ability).find);
console.log('findOne', ArticleModel.accessibleBy(ability).findOne);
console.log('findById', ArticleModel.accessibleBy(ability).findById);
find [Function (anonymous)]
findOne [Function (anonymous)]
findById undefined

TypeError: ArticleModel.accessibleBy(...).findById is not a function

@stalniy
Copy link
Owner

stalniy commented Oct 16, 2022

accessibleBy returns mongoose.Query. So if method undefined then it was removed by mongoose author

@Alex0007
Copy link

@stalniy
Screenshot 2022-10-17 at 03 42 21

Method is still there

console.log('1', ArticleModel.findById('test').accessibleBy(ability).getQuery());
console.log('2', ArticleModel.accessibleBy(ability).findById('test').getQuery());

Output:

1 { _id: 'test', '$and': [ {} ] }
TypeError: ArticleModel.accessibleBy(...).findById is not a function

@stalniy
Copy link
Owner

stalniy commented Oct 17, 2022

There are 2 types of methods:

  • static “class”/model methods
  • query methods

What you need to check is ArticleModel.find().findById()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants