getMany<Model>(collection: Collection<Model>, ids: keyof string[], onMissing?: function | "ignore"): Promise<Doc<Model>[]>
Retrieves multiple documents from a collection.
You can specify a strategy to handle missing documents by passing the onMissing argument.
By default, missing documents will throw an error. Other strategies:
By providing (id) => new MyModel(id, ...), you can provide a default value when a doc is missing
By providing 'ignore', missing documents are ignore and will be removed from the result
By providing (id) => throw new CustomError(id), you can throw a a custom error
Retrieves multiple documents from a collection.
You can specify a strategy to handle missing documents by passing the
onMissing
argument. By default, missing documents will throw an error. Other strategies:(id) => new MyModel(id, ...)
, you can provide a default value when a doc is missing'ignore'
, missing documents are ignore and will be removed from the result(id) => throw new CustomError(id)
, you can throw a a custom errorimport { getMany, collection } from 'typesaurus' type User = { name: string } const users = collection<User>('users') getMany(users, ['00sHm46UWKObv2W7XK9e', '00sHm46UWKObv2W7XK0d']).then(user => { console.log(user) //=> [ { __type__: 'doc', data: { name: 'Sasha' }, ... }, { __type__: 'doc', data: { name: 'Thomas' }, ... }] })