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.

Check the model type when using `findById`

See original GitHub issue

I’m not quite sure if it’s a bug, but the behavior of ottoman doesn’t match my assumption.

I have a use case that uses uuid without prefix as the key of a document, and multiple models reside in a single bucket/scope/collection. The problem is that when applying an Id of model A to ModelB.findById, it just returns the document of model A.

I know it’s not expected to apply the wrong Id to the model.findById, but it would be ideal if it can return a DocumentNotFoundError instead of a data from other models.

Attaching a minimum reproducible code as follows, https://gist.github.com/xavierchow/a995771877a9bac3ff56e192ae3aef2f

I’m wondering if an improvement with checking the model type for findById makes sense?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gsi-alejandrocommented, May 3, 2022

Hi @xavierchow, thank you for your feedback.

We will provide a solution for its next release (check for doc _type against the model)

0reactions
gsi-alejandrocommented, Oct 18, 2022

released on version 2.2.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement findById in two different Model using Node ...
Currently, this is the code that I have but it only implements in only one of the models which is the User. jwt.verify(token,...
Read more >
Use Model.findById() to Search Your Database By _id
In this MongoDB and Mongoose tutorial we use Model. findById () to search your database by _id. This is one section of many...
Read more >
Find By ID in Mongoose - Mastering JS
In Mongoose, the Model.findById() function is used to find one document by its _id . The findById() function takes in a single parameter, ......
Read more >
Retrieving Your Data - 2.x - CakePHP Cookbook
The most common function you will use in models is Model::find() ... $params is used to pass all parameters to the various types...
Read more >
The Spring Data JPA findById Anti-Pattern - Vlad Mihalcea
In this article, we are going to see how the Spring Data JPA findById method can become an Anti-Pattern when using it to...
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