> For the complete documentation index, see [llms.txt](https://sebloix.gitbook.io/gstore-node/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sebloix.gitbook.io/gstore-node/v8.x/queries/findone.md).

# findOne()

Quickly find an entity by passing key/value pairs. You can optionally pass an ancestors array or a namespace.

**@Returns** an gstore entity **instance** of the Model.

This method accepts the following arguments:

```javascript
MyModel.findOne(
    /* {object}. -- Key/Value pairs to look for */
    <propsValues>,
    /* {Array} -- optional. ex: ['ParentEntity', 1234 ] */
    <ancestors>,
    /* {string} -- optional. A specific namespace */
    <namespace>,
    /* {object}. -- optional. Options for the query */
    <options>
)
```

## options

The options argument accepts the following properties:

* **cache** (default: the "global" cache configuration)\
  "true" = read from the cache and prime the cache with the query response.
* **ttl** (default: the global `cache.ttl.queries` value) Custom TTL value for the cache. For multi-store it can be an *Object* of TTL values.
* **readAll** (default: false). Return all the properties, even the ones marked as `read: false` on the Schema.

Example:

```javascript
const User = require('./user.model');

User.findOne({ email: 'john@snow.com' })
    .then((entity) => {
        console.log(entity.plain()); // entityData + id
        console.log(entity.firstname)); // 'John'
});

// Disable cache and read all properties
User.findOne({ email: 'john@snow.com' }, null, null, { cache: false, readAll: true })
    .then((entity) => {
        console.log(entity.plain()); // entityData + id
        console.log(entity.firstname)); // 'John'
});

// Custom TTL for cache
// ttl set to "-1" means to not cache for this store
User.findOne({ email: 'john@snow.com' }, null, null, { ttl: { memory: -1, redis: 300 } })
    .then((entity) => {
        console.log(entity.plain()); // entityData + id
        console.log(entity.firstname)); // 'John'
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sebloix.gitbook.io/gstore-node/v8.x/queries/findone.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
