Issuing ProvenDB commands

ProvenDB commands are implemented as standard MongoDB commands. You can issue them using the runCommand or command methods provided by the MongoDB shell. Examples are provided below in several programming environments. Consult your database driver documentation if the syntax for your specific driver is not listed here.

MongoDB Shell

In the MongoDB shell, commands can be issued using the runCommand method of the db object. Most of the examples in this manual use the MongoDB shell, since it's generally familiar to all developers. Here is an example of issuing a getVersion command in the mongo shell:

Mongo Shell>db.runCommand({getVersion:1});
	"ok" : 1,
	"response" : "The version is set to: 'current'",
	"version" : NumberLong(36496),
	"status" : "current"

MongoDB Java driver

In the MongoDB java driver, use the runCommand methods of the MongoDatabase object to issue ProvenDB commands, as shown below:

MongoClient mongoClient = new MongoClient();
MongoDatabase database = mongoClient.getDatabase("test");

Document getVersionResults = database.runCommand(new Document("getVersion", 1));

MongoDB node driver

In NodeJS, we use the command method of the database object to call ProvenDB commands:

const provenDbUri = process.env.PROVENDB_URI;
async function main() {
  const MongoClient = require('mongodb').MongoClient;
  const mongoclient = await MongoClient.connect(provenDbUri, {useNewUrlParser: true});
  const mongodb = mongoclient.db();
  const getVersionOut = await mongodb.command({getVersion: 1});
  console.log('The version is', getVersionOut.version);


Asynchronous programming in Javascript

Like other MongoDB commands, ProvenDB commands execute asynchronously. Consequently, you will need to use one of the Javascript asynchronous idioms: callbacks, Promises, or async/await syntax. The example above uses the async/await syntax. See the documentation for the MongoDB NodeJS driver here for more information.

MongoDB python driver

In python ProvenDB commands are issued by calling the command method from the MongoClient object:

from pymongo import MongoClient


print 'The version is %s' % (getVersionOutput.version)

MongoDB Go Driver

In the Go driver, ProvenDB commands are issued by calling the RunCommand method from a database object:

	database := client.Database(conn.Database)
	// get the current version
	result := database.RunCommand(ctx, bson.D{{"getVersion", 1}})
	if result.Err() != nil {
	var d bson.D
	err := result.Decode(&d)
	if err != nil {
	version := d.Map()["version"].(int64)
	t.Logf("the current version is %d", version)

What’s Next