findOne with additional constraints
See original GitHub issueProblem
Currently, you can only select by unique fields in findOne
. I want to be able to add additional constraints in findOne. For example, find a record by ID that also satisfies some proprerty:
TodoItem.findOne({
where: {
id: 10,
user: {
id: 100
}
}
})
Solution
I want to be able to select by different additional properties in findOne. Maybe require at least one unique property, but also allow other properties. That doesn’t change the fact the findOne will always return at most a single record.
This is similar to #1167 but I just want to be able to select by additional properties to @unique
properties.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:12 (4 by maintainers)
Top Results From Across the Web
node.js - mongoose findOne() query called last in function
I am having trouble running my mongoose findOne() query in a synchronous fashion within a function. Here is my code: exports.read = function(req, ......
Read more >Model Querying - Finders - Sequelize
The findOne method obtains the first entry it finds (that fulfills the optional query options, if provided). const project = await Project.
Read more >db.collection.findOne() — MongoDB Manual
Specifies additional options for the query. These options modify query behavior and how results are returned. To see available options, see FindOptions.
Read more >Mongoose v6.8.1: API docs
This function is similar to isValidObjectId() , but considerably more strict, because isValidObjectId() will return true for any value that Mongoose can ...
Read more >How to add unique constraint in collection of MongoDB using ...
Mongoose module is one of the most powerful external modules of the node.js.Mongoose is a MongoDB ODM i.e (Object database Modelling) that ...
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
This doesn’t seem to solve the update or delete use cases mentioned in https://github.com/prisma/prisma/issues/1924#issuecomment-643599101. Maybe that should be a new issue. I added more detail here https://github.com/prisma/prisma/discussions/4185#discussioncomment-338913.
All good, that is what I am here for 🤣