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.

findOne with additional constraints

See original GitHub issue

Problem

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:closed
  • Created 3 years ago
  • Reactions:22
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
OzzieOrcacommented, Feb 4, 2021

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.

2reactions
janpiocommented, Sep 13, 2022

All good, that is what I am here for 🤣

Read more comments on GitHub >

github_iconTop 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 >

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