Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findOneByFields - new method #112

Open
RemyMachado opened this issue Oct 5, 2022 · 2 comments
Open

findOneByFields - new method #112

RemyMachado opened this issue Oct 5, 2022 · 2 comments

Comments

@RemyMachado
Copy link

RemyMachado commented Oct 5, 2022

I am wondering why isn't there a findOneByFields method, similar to the existing findByFields one.

Currently I'm using this hack:

    async findOneByFields(values) {
        return this.findByFields(values).then((documents) => documents?.[0])
    }

Is there a reason why it's not provided?

Is my wrapping function useless because of how the batching/caching work?

@lorensr
Copy link
Member

lorensr commented Oct 8, 2022

No reason I know of. Batching and caching should work with your helper

@RemyMachado RemyMachado changed the title findOneByField - new method findOneByFields - new method Oct 31, 2022
@richardcarrigan
Copy link
Contributor

Not that I think it's necessary, but one major use case for this would be authenticated queries where it's necessary to identify the user trying to access the document.

Example:

async findOneByFields(documentId, userId) {
    return this.findByFields({ _id: documentId, userId }).then(documents => documents?.[0]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants