@textile/hub > Client > findByID
Client.findByID() method
Queries the collection by a known instance ID.
Signature:
findByID<T = unknown>(threadID: ThreadID, collectionName: string, ID: string): Promise<T>;
Parameters
Parameter | Type | Description |
---|---|---|
threadID | ThreadID | the ID of the database |
collectionName | string | The human-readable name of the model to use. |
ID | string | The id of the instance to search for. |
Returns:
Promise<T>
Example 1
Find and cast a known model by instance ID.
import {Client, ThreadID} from '@textile/hub'
interface Astronaut {
name: string
missions: number
_id: string
}
async function getAstronaut (client: Client, threadID: ThreadID, id: string) {
const astronaut = await client.findByID<Astronaut>(threadID, 'astronauts', id)
return astronaut
}
Example 2
Simple find and return any instance
import {Client, ThreadID} from '@textile/hub'
async function getInstance (client: Client, threadID: ThreadID, id: string) {
return await client.findByID(threadID, 'astronauts', id)
}