HCL OneDB JSON commands
The HCL OneDB™ JSON commands are available in addition to the supported MongoDB commands. These commands enable functionality that is supported by HCL OneDB and they are run by using the MongoDB API.
The syntax for using HCL
OneDB
commands in the MongoDB shell is:
db.runCommand({command_document})
The
command_document contains the HCL
OneDB command and any parameters.createTextIndex
Create HCL OneDB Basic Text Search (BTS) indexes.
Important: If you create text indexes by using the HCL
OneDB createTextIndex
command, you must query them by using the HCL
OneDB $ifxtext
query operator. If you create text indexes by using the MongoDB syntax
for text indexes, you must query them by using the MongoDB $text
query operator.
- createTextIndex
- This required parameter specifies the name of the collection or relational table where the BTS index is created.
- name
- This required parameter specifies the name of the BTS index.
- options
- This required parameter specifies the name-value pairs for the BTS parameters that are used when creating the index. If no parameter values are required, you can specify an empty document.
- key
- This parameter is required if you are indexing relational tables, but optional if you are indexing collections. This parameter specifies which columns to index for relational tables.
exportCollection
Export JSON collections from the wire listener to a file.
- exportCollection
- This required parameter specifies the collection name to export.
- file
- This required parameter specifies the output file path on the
host machine where the wire listener is running. For example:
- UNIX™ is
file:"/tmp/export.out"
- Windows™ is
file:"C:/temp/export.out"
- UNIX™ is
- format
- This required parameter specifies the exported file format.
- json
- Default. The .json file format. One JSON-serialized document per line is exported.
- jsonArray
- The .jsonArray file format. This format exports an array of JSON-serialized documents with no line breaks. The array format is JSON-standard.
- csv
- The .csv file format. Comma-separated values are exported. You must specify which fields to export from each document. The first line of the .csv file contains the fields and all subsequent lines contain the comma-separated document values.
- fields
- This parameter specifies which fields are included in the output file. This parameter is required for the csv format, but optional for the json and jsonArray formats.
- query
- This optional parameter specifies a query document that identifies which documents are
exported. The following example exports all documents from the collection that is named
c that have a "qty" field that is less than 100:
> db.runCommand({exportCollection: "c", file: "/tmp/export.out", format: "json", query: {"qty": {"$lt": 100}}})
importCollection
Import JSON collections from the wire listener to a file.
- importCollection
- The required parameter specifies the collection name to import.
- file
- This required parameter specifies the input file path. For example,
file: "/tmp/import.json"
.Important: The input file must be on the same host machine where the wire listener is running. - format
- This required parameter specifies the imported file format.
- json
- Default. The .json file format.
- jsonArray
- The .jsonArray file format.
- csv
- The .csv file format.
lockAccounts
Lock a database or user account.
Important:
- To run this command, you must be the instance administrator.
- If you specify the
lockAccounts:1
command without specifying a db or user argument, all accounts in all databases are locked.
- lockAccounts:1
- This required parameter locks a database or user account.
- db
- This optional parameter specifies the database name of an account to lock. For
example, to lock all accounts in database that is named
foo
: - user
- This optional parameter specifies the user accounts to lock. For example, to lock
the account of all users that are not named
alice
:> db.runCommand({lockAccounts: 1, user: {$ne: "alice"}});
runFunction
Run an SQL function through the wire listener. This command is equivalent to the SQL statement EXECUTE FUNCTION.
- runFunction
- This required parameter specifies the name of the SQL function to run. For example, a
current function returns the current date and
time:
> db.runCommand({runFunction: "current"}) {"returnValue": 2016-04-05 12:09:00, "ok":1}
- arguments
- This parameter specifies an array of argument values to the function. You must provide as many
arguments as the function requires. For example, an add_values function requires
two arguments to add
together:
The following example returns multiple values from a func_return3 function:> db.runCommand({runFunction: "add_values", "arguments": [3,6]}) {"returnValue": 9, "ok": 1}
> db.runCommand({runFunction: "func_return3", "arguments" :[101]}) {"returnValue": {"serial_num": 1103, "name": "Newton", "points": 100}, "ok": 1}
runProcedure
Run an SQL stored procedure through the wire listener. This command is equivalent to the SQL statement EXECUTE PROCEDURE.
- runProcedure
- This required parameter specifies the name of the SQL procedure to run. For example, a
colors_list stored procedure, which uses a WITH RESUME clause in its RETURN
statement, returns multiple rows about
colors:
> db.runCommand({runProcedure: "colors_list"}) {"returnValue": [ {"color" : "Red","hex" : "FF0000"}, {"color" : "Blue","hex" : "0000A0"}, {"color" :"White","hex" : "FFFFFF"} ], "ok" : 1}
- arguments
- This parameter specifies an array of argument values to the procedure. You must provide as many
arguments as the procedure requires. For example, an increase_price procedure
requires two arguments to identify the original price and the amount of
increase:
> db.runCommand({runProcedure: "increase_price", "arguments": [101, 10]}) {"ok":1}
transaction
Enable or disable transaction support for a session, run a batch transaction, or, when
transaction support is enabled, commit or rollback transactions. This command binds or unbinds a
connection to the current MongoDB session in
a database. The relationship between a MongoDB session and the HCL
OneDB JDBC connection
is not static.
Important: This command is not supported for queries that are run on
shard servers.
- enable
- This optional parameter enables transaction mode for the current session in the
current database. The following example shows how to enable transaction
mode:
> db.runCommand({transaction: "enable"}) {"ok":1}
- disable
- This optional parameter disables transaction mode for the current session in the
current database. The following example shows how to disable for transaction mode:
> db.c.find() {"_id":ObjectId("52a8f9c477a0364542887ed4"),"a":1} > db.runCommand({transaction: "disable"}) {"ok":1}
- commit
- If transactions are enabled, this optional parameter commits the current transaction. If
transactions are disabled, an error is shown. The following example shows how to commit
the current
transaction:
> db.c.insert({"a": 1}) > db.runCommand({transaction: "commit"}) {"ok":1}
- rollback
- If transactions are enabled, this optional parameter rolls back the current transaction. If
transactions are disabled, an error is shown. The following example shows how to roll
back the current
transaction:
> db.c.insert({"a": 2}) > db.c.find() {"_id":ObjectId("52a8f9c477a0364542887ed4"),"a":1} {"_id":ObjectId("52a8f9e877a0364542887ed5"),"a":2} > db.runCommand({transaction: "rollback"}) {"ok":1}
- execute
- This optional parameter runs a batch of commands as a single transaction. If transaction mode is not enabled for the session, this parameter enables transaction mode for the duration of the transaction.
- status
- This optional parameter prints status information to indicate whether transaction mode
is enabled, and if transactions are supported by the current database. The following
example shows how to print status
information:
> db.runCommand({transaction: "status"}) {"enabled": true, "supports": true, "ok": 1}
unlockAccounts
Unlock
a database or user account.
Important:
- To run this command, you must be the instance administrator.
- If you specify the
unlockAccounts:1
command without specifying a db or user argument, all accounts in all databases are unlocked.
- unlockAccounts:1
- This required parameter unlocks a database or user account.
- db
- This optional parameter specifies the database name of an account to unlock. For example, to
unlock all accounts in database that is named
foo
:> db.runCommand({unlockAccounts: 1, db: "foo"})
- user
- This optional parameter specifies the user accounts to unlock. For example, to unlock the
account of all users that are not named
alice
:> db.runCommand({unlockAccounts: 1, user: {$ne: "alice"}});