Skip to main content

Dataset

Dataset is a secondary unit in Glacier, similar to the MongoDB database, but each Dataset must belong to a Namespace.

The code for creating Dataset is as follows, you need to get Namespace to which it belongs through client.namespace(name) firstly:

src/createDataset.ts
async function createDataset() {
const myproject = client.namespace('myproject');
const result = await myproject.createDataset('mydataset');
console.log(result);
}

Output result:

{
insertedId: 'mydataset';
}

If you want to query the details of a Dataset, you can use the queryDataset method provided by Namespace, the example is as follows:

src/queryDataset.ts
async function queryDataset() {
const myproject = client.namespace('myproject');
const result = await myproject.queryDataset('mydataset');
console.log(result);
}

Output result:

{
owner: '0xb4c42d4b15aa65f782b81ac01eaba2472f83b4e9',
network: 'ethereum',
namespace: 'myproject',
dataset: 'mydataset',
seqId: 0,
collections: [
{
collection: 'notes',
owner: '0xb4c42d4b15aa65f782b81ac01eaba2472f83b4e9',
network: 'ethereum',
schema: '{"title":"notes","type":"object","properties":{"title":{"type":"string","title":"","description":""},"content":{"type":"string","title":"","description":""},"createdAt":{"type":"number","title":"","description":""}},"required":["title","content","createdAt"]}',
seqId: 0,
createdAt: 1672069218,
updatedAt: 1672069218
}
],
createdAt: 1672036876,
updatedAt: 1672069218
}

collections from the above codes is Collection contained in this Dataset.