Check the model type when using `findById`
See original GitHub issueI’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:
- Created a year ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @xavierchow, thank you for your feedback.
We will provide a solution for its next release (check for doc _type against the model)
released on version 2.2.1