CreateDatabase

CreateDatabase( param_object )
CreateDatabase( param_object )
CreateDatabase( param_object )
CreateDatabase( param_object )
create_database( param_object )
CreateDatabase( param_object )

Description

The CreateDatabase function adds a new database to the cluster with the specified parameters. It requires an admin key for authentication.

Parameters

Argument Type Definition and Requirements

param_object

The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements

name

The name of a database. Databases cannot be named any of the following reserved words: events, set, self, documents, or _.

data

Optional - A JSON object to contain user-defined metadata for the database. It is provided for the developer to store information at the database level.

priority

Optional - A relative weight between 1 and 500, inclusive, indicating how many resources this database is allowed to utilize. Defaults to 1. A higher number means more resources.

The priority option is deprecated as of release 2.10.0. You should avoid specifying priority. In some future Fauna release, priority will be removed. See Deprecations for more details.

Returns

An object containing the metadata of CreateDatabase operations.

Field Name Field Type Definition and Requirements

ref

A Reference to the database that was created.

name

The name of the database just created.

ts

The timestamp, with microsecond resolution, associated with the creation of the database.

data

Included only when specified during database creation. An object containing user-defined metadata for this database.

global_id

A read-only string that provides a globally-unique identifier for this database.

Examples

The following query creates a database named "db-next" and returns the reference to the database, the name of the database, and the time the database was created:

try
{
    Value result = await client.Query(
        CreateDatabase(Obj("name", "db-next"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "db-next", collection = RefV(id = "databases")),ts: LongV(1603756177320000),name: StringV(db-next),global_id: StringV(yx1enifpkybyy))
result, err := client.Query(
	f.CreateDatabase(f.Obj{"name": "db-next"}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[global_id:yx18tp8ogydyy name:db-next ref:{db-next 0xc0000ad290 0xc0000ad290 <nil>} ts:1603747134420000]
System.out.println(
    client.query(
        CreateDatabase(Obj("name", Value("db-next")))
    ).get());
{ref: ref(id = "db-next", collection = ref(id = "databases")), ts: 1593464629200000, name: "db-next", global_id: "yq9nin7xhybyy"}
client.query(
  q.CreateDatabase({ name: 'db-next' })
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  ref: Database("db-next"),
  ts: 1592054207370000,
  name: 'db-next',
  global_id: 'yqhq17umsybyy'
}
result = client.query(
    q.create_database({"name": "db-next"})
)
print(result)
{'ref': Ref(id=db-next, collection=Ref(id=databases)), 'ts': 1592856487080000, 'name': 'db-next', 'global_id': 'yq76pr57aybyy'}
try {
  println(Await.result(
    client.query(CreateDatabase(Obj("name" -> "db-next"))),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{ref: ref(id = "db-next", collection = ref(id = "databases")), ts: 1594485000640000, name: "db-next", global_id: "yxy9xjqqqybyy"}

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!