@textile/hub > Client > find
Client.find() method
Queries a collection for entities matching the given query parameters.
Signature:
find<T = unknown>(threadID: ThreadID, collectionName: string, query: QueryJSON): Promise<T[]>;
Parameters
Parameter | Type | Description |
---|---|---|
threadID | ThreadID | the ID of the database |
collectionName | string | The human-readable name of the model to use. |
query | QueryJSON | The object that describes the query. User Query class or primitive QueryJSON type. |
Returns:
Promise<T[]>
Example
Query with return type
import {Client, ThreadID, Where} from '@textile/hub'
interface Astronaut {
name: string
missions: number
_id: string
}
async function getAstronautByName (client: Client, threadID: ThreadID, name: string) {
const query = new Where('name').eq(name)
const astronaut = await client.find<Astronaut>(threadID, 'astronauts', query)
return astronaut
}