# Global Document

See Documents Section for further information on documents.

# useGlobal

When creating a global document, it will always come with an identifier.

You should also specify a data type for your global document.

type MyDataType = {
    _id: string;
    identifier: string;
    totalMoneyCreated: number;
    totalMoneyDestroyed: number;
};

async function someFunction() {
    const document = await Rebar.document.global.useGlobal<MyDataType>('my-cool-global-document');
}

# get

Get the entire document of data.

async function doSomething() {
    const document = await Rebar.document.global.useGlobal<MyDataType>('my-identifier-goes-here-for-my-document');
    const data = document.get();
    console.log(data);
}

# getField

Get a specific field from the document. These may return undefined.

async function doSomething() {
    const document = await Rebar.document.global.useGlobal<MyDataType>('my-identifier-goes-here-for-my-document');

    const totalMoneyCreated = document.getField('totalMoneyCreated');
    console.log(totalMoneyCreated);
}

# set

Set a specific field for the document.

async function doSomething() {
    const document = await Rebar.document.global.useGlobal<MyDataType>('my-identifier-goes-here-for-my-document');
    document.set('totalMoneyCreated', 200);
}

# setBulk

Set multiple fields for the document.

async function doSomething() {
    const document = await Rebar.document.global.useGlobal<MyDataType>('my-identifier-goes-here-for-my-document');
    document.setBulk({ totalMoneyCreated: 200, totalMoneyDestroyed: 200 });
}