About Compartments

Learn how to specify the compartment while creating and working with Oracle NoSQL Database Cloud Service tables using Oracle NoSQL Database Drivers.

Oracle NoSQL Database Cloud Service tables are created in a compartment and are scoped to that compartment. When authenticated as a specific user, your tables are managed in the root compartment of your tenancy unless otherwise specified. Organizing tables into different compartments will help concerning organization and security.

If you have been authenticated using an instance principal (accessing the service from an OCI compute instance), you must specify a compartment using its id (OCID), as there is no default in this case. See Calling Service From an Instance in Oracle Cloud Infrastructure Documentation.

There are several ways to specify a compartment in your application code:
  1. Use a default compartment in NoSQLHandleConfig so that it applies to all the operations using the handle. See Obtaining a NoSQL Handle for an example.
  2. Use the compartment name or id (OCID) in each request in addition to the table name. This overrides any default compartment.
    For example:
    GetRequest getReq = new GetRequest().setTableName("mytable")
                                        .setCompartment("mycompartment");
  3. Use the compartment name as a prefix on the table name. This overrides any default compartment as well as a compartment specified using API.
    For example:
    GetRequest getReq = new GetRequest().setTableName("mycompartment:mytable");
When using a named compartment, the name can be the simple name of a top-level compartment or a path to a nested compartment. In the latter case, the path is a "." (dot) separated path.

Note:

While specifying the path to a nested compartment, do not include the top-level compartment's name in the path as that is inferred from the tenancy.
There are several ways to specify a compartment in your application code:
  • A method exists to allow specification of a default compartment for requests in borneo.NoSQLHandleConfig.set_compartment(). This overrides the user’s default compartment.
  • In addition, it is possible to specify a compartment in each Request instance.
The set_compartment methods take either an id (OCID) or a compartment name or a path. If a compartment name is used it may be the name of a top-level compartment.

Note:

If a compartment path is used to reference a nested compartment, the path is a dot-separate path that excludes the top-level compartment of the path, for example, compartmentA.compartmentB.
Instead of setting a compartment in the request, it is possible to use a compartment name to prefix a table name in a request, query, or DDL statement. This usage overrides any other setting of the compartment. For example,
...
request = PutRequest().set_table_name('mycompartment:mytable')
...
create_statement = 'create table mycompartment:mytable(...)' 
...
request = GetRequest().set_table_name('compartmentA.compartmentB')
There are several ways to specify a compartment in your application code:
  • You can set a desired compartment name or id.
  • Set to an empty string to use the default compartment, that is the root compartment of the tenancy.
  • If using a nested compartment, specify the full compartment path relative to the root compartment as compartmentID. For example, if using rootCompartment.compartmentA.compartmentB, the compartmentID should be set to compartmentA.compartmentB.
  • You can also use the compartment OCID as the string value.
compartmentID:="<optional-compartment-name-or-ID>"
iam.NewRawSignatureProvider(tenancy, user, region, fingerprint, compartmentID,
        privateKey, &privateKeyPassphrase)
You can specify a default compartment for all operations performed by a NoSQLClient instance by setting the compartment property of the configuration passed to the NoSQLClient constructor:
import { NoSQLClient,Region } from 'oracle-nosqldb';
const client = new NoSQLClient({
    region: Region.US_ASHBURN_1,
    compartment: 'mycompartment'
});

The string value may be either a compartment id or a compartment name or path. If it is a simple name it must specify a top-level compartment. If it is a path to a nested compartment, the top-level compartment must be excluded as it is inferred from the tenancy. A compartment can also be specified in each request in the options object. This value overrides the initial configuration value.

If you don't specify a compartment, the root compartment of the tenancy will be used as the default. This applies only if you are authorizing with specific user's identity. If you are using instance principal or resource principal for authentication, you must specify the compartment ID as there is no default in these cases.

If compartment is not supplied, the tenancy OCID will be used as default. Note this only applies if you are authorizing with user's identity. When using instance principal or resource principal, compartment id must be specified.

For the procedure to set up instance principal, seeCalling Services from an Instance. For the procedure to set up resource principal, see Accessing Other Oracle Cloud Infrastructure Resources from Running Functions.

The default compartment for tables is the root compartment of the user's tenancy. A default compartment for all operations can be specified by setting the Compartment property of NoSQLConfig. For example:
var client = new NoSQLClient(
    new NoSQLConfig
    {
        Region=Region.US_ASHBURN_1,
        Compartment="<compartment_ocid_or_name>"
    });
The string value may be either a compartment OCID or a compartment name or path. If it is a simple name it must specify a top-level compartment. If it is a path to a nested compartment, the top-level compartment must be excluded as it is inferred from the tenancy.

In addition, all operation options classes have Compartment property, such as TableDDLOptions.Compartment, GetOptions.Compartment, PutOptions.Compartment, etc. Thus you may also specify comparment separately for any operation. This value, if set, will override the compartment value in NoSQLConfig, if any.

If compartment is not supplied, the tenancy OCID will be used as default. Note this only applies if you are authorizing with user's identity. When using instance principal or resource principal, compartment id must be specified.

Related Topics