question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mongoose `.orFail()` does not work when permissions are implicitly denied

See original GitHub issue

I ran into this issue accidentally today, but the way my application is set up, it expends models not found to throw an error.

ex:

    var user = await User.findById(req.params.id)
      .accessibleBy(req.ability)
      .orFail();

    res.json({ user });

When the permission to view users is set, it works fine and dandy. The conditions for this query were { _id: '5d600d0ea21964033b4fc1bb', '$and': [ {} ] }.

But if the permission is implicitly denied, the conditions are { _id: '5d600d0ea21964033b4fc1bb', __forbiddenByCasl__: 1 }. The problem is though that the user variable is returning null, and not throwing an exception.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stalniycommented, Sep 14, 2019

fixed in @casl/mongoose@2.3.2.

Thanks for the issue!

1reaction
stalniycommented, Aug 26, 2019

Thanks, I didn’t know about orFail method of mongoose Query 😃

I think this is a bug but I’ll need some time to confirm this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express Handlebars denied access to mongoose object
One solution may be to put a .lean() on my mongoose methods. There must be a cleaner way. Any ideas of a resolution...
Read more >
mongoose | Yarn - Package Manager
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports Node.js and Deno (alpha).
Read more >
Mongoose v6.8.2: API docs
Used for declaring paths in your schema that should be 128-bit decimal floating points. Do not use this to create a new Decimal128...
Read more >
Access is denied. : Permission denied Reason: 13 - MongoDB
Open a Command Prompt with Administrative privileges. Ctrl + Shift + Click on Control Prompt. Run (The path to mongo executables is enter...
Read more >
Express Tutorial Part 3: Using a Database (with Mongoose)
Note: You don't need to know MongoDB in order to use Mongoose, ... results==null ) or daisy chain the orFail() method on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found