@textile/hub > Client > newCollectionFromObject
Client.newCollectionFromObject() method
newCollectionFromObject creates and registers a new collection under the given name. The input object must be serializable to JSON, and contain only json-schema.org types.
Signature:
newCollectionFromObject(threadID: ThreadID, obj: Record<string, any>, config: Omit<CollectionConfig, 'schema'>): Promise<void>;
Parameters
Parameter | Type | Description |
---|---|---|
threadID | ThreadID | the ID of the database |
obj | Record<string, any> | The actual object to attempt to extract a schema from. |
config | Omit<CollectionConfig, 'schema'> | A configuration object for the collection. See CollectionConfig. |
Returns:
Promise<void>
Example
Change a new astronauts collection based of Buzz
import {Client, ThreadID} from '@textile/hub'
async function newCollection (client: Client, threadID: ThreadID) {
const buzz = {
name: 'Buzz',
missions: 2,
_id: '',
}
return await client.newCollectionFromObject(threadID, buzz, { name: 'astronauts' })
}