mapr dbshell

The mapr dbshell is a tool for the creation and the lightweight manipulation of JSON tables and documents.

Before running the shell, ensure that your user ID has both the readAce and writeAce permissions on the volume. For information about these permissions, see Whole Volume ACEs.

To run the shell, enter mapr dbshell on the command line after logging into a node in a MapR cluster.

Note: You might see these messages when you run the shell on SUSE Linux:
[INFO] Unable to bind key for unsupported operation: backward-delete-word
[INFO] Unable to bind key for unsupported operation: up-history
[INFO] Unable to bind key for unsupported operation: down-history
To suppress the messages, you can edit the /etc/inputrc file rename the keywords that are specified in the messages:
Original name New name
backward-delete-word backward-kill-word
down-history next-history
up-history previous-history

Although you can run the command help to see a full list of commands that it supports, a number of important commands are described below.

  • create
  • delete
  • drop
  • find and findbyid
  • insert
  • jsonoptions
  • list

Creating JSON Tables

Run the command create, specifying the path in the MapR filesystem in which to create the table.

Example
create /data/movies

When you create a JSON table in the mapr dbshell, the default column family is created automatically. There are no commands for creating additional column families. To create any, exit the shell and use the command maprcli table cf create.

Deleting JSON Documents

Run the delete command to delete a single OJAI document. Specify the path of the table in which the document is located and the ID of the document.

Example
delete /data/movies --id movie0000002

Dropping JSON Tables

Run the command drop, specifying the path to the JSON table in the MapR filesystem.

Example
drop /data/movies

Querying JSON Documents

Run either the find or findbyid command.

Examples

find /data/movies
Returns all of the documents that are in the table /data/movies.
find /data/movies --fromid movie0000001 --toid movie0000100
Returns all of the documents within a range of IDs that includes the specified starting ID and excludes the specified ending ID.
findbyid /data/movies --id movie0000002
Returns the document that has the specified ID.

Options

--pretty
Values: true, false
Specifies whether to display the content of OJAI documents as an indented hierarchy of field/value pairs.
--withTags
Values: true, false
Specifies whether to show tags for extended JSON data types. For example, if the value is true, the DATE data type appears as a Map:
"dob" : {"$dateDay":"2012-10-20"}
If the value is false, the DATE data type appears as a simple value:
"dob" : "2012-10-20"
For more about the supported extended data types and the their tags, see .

Adding Documents to JSON Tables

Run the insert command. Specify the ID of the document in either of two ways:
  • As the value of the _id field in the document
  • As the value of the --id parameter of the insert command
Examples
insert /data/movies --value '{"_id":"movie0000002" , "title":"Developers 
on the Edge", "studio":"Command Line Studios"}'
insert /data/movies --id movie0000003 --value '{"title":"The Golden Master", 
"studio":"All-Nighter"}'

Options for displaying OJAI documents

Run the command jsonoptions to change how the content of OJAI documents is displayed. There are two options:
pretty
Values: true, false
Specifies whether to display the content of OJAI documents as an indented hierarchy of field/value pairs.
withTags
Values: true, false
Specifies whether to show tags for extended JSON data types. For example, if the value is true, the DATE data type appears as a Map:
"dob" : {"$dateDay":"2012-10-20"}
If the value is false, the DATE data type appears as a simple value:
"dob" : "2012-10-20"
For more about the supported extended data types and the their tags, see .

Listing JSON Tables

Run the command list, specifying a path in the MapR filesystem.

Example
list /data