Command line interface

EJDB command line interface is provided as the part of ejdb-node module published in Nodejs Package Manager(NPM) repository.


You need the ejdb-node module being installed on your system, follow the ejdb-node installation guide to do this.

Program options

The ejdb program has the following options:

-h, --help

Display usage summary and ejdb version.

-n, --no-colors

Do not use colored output.

-q, --quiet

Run in quiet output mode

-c, --cmd

Run the specified javascript command

Usage demo

$ ejdb
Welcome to EJDB CLI v1.2.6-1

This is javascript interpreter with db and EJDB objects in the context, to describe db just type: db <ENTER>

ejdb> db
{ open: [Function] (dbFile, [openMode], [cb]) Open database,
  status: [Function] Get current database status,
  close: [Function] ([cb]) Close database }

Let’s open/create db:

{ file: '/home/adam/mydb', collections: [] }

For opened database we have more methods to operate:

  close: [Function] ([cb]) Close database,
  status: [Function] Get current database status,
  find: [Function] (cname, [qobj], [qobjarr], [hints], [cb])
        Execute query on collection,
  ensureCollection: [Function] (cname, [copts], [cb])
        Creates new collection if it does't exists,
  dropCollection: [Function] (cname, [prune], [cb])
                  Drop collection, if `prune` is true collection
                  db files will be erased from disk.,
  save: [Function] (cname, object|array of object, [opts], [cb])
                    Save/update specified JSON objects in the collection.,
  update: [Function] (cname, [qobj], [qobjarr], [hints], [cb])
                     Perform update query on collection,
  isOpen: [Function] Check if database in opened state,
  removeCollection: [Function],
  load: [Function] (cname, oid, [cb])
                    Loads object identified by OID from the collection,
  remove: [Function] (cname, oid, [cb]) Removes object from the collection,
  findOne: [Function] (cname, [qobj], [qobjarr], [hints], [cb])
                      Retrive one object from the collection,
  command: [Function],
  count: [Function] (cname, [qobj], [qobjarr], [hints], [cb])
                    Convenient count(*) operation,
  sync: [Function] Synchronize entire EJDB database with disk,
  dropIndexes: [Function] (cname, path, [cb])
                          Drop indexes of all types for JSON field path,
  optimizeIndexes: [Function] (cname, path, [cb])
                              Optimize indexes of all types for JSON field path,
  ensureStringIndex: [Function] (cname, path, [cb])
                                Ensure String index for JSON field path,
  rebuildStringIndex: [Function] (cname, path, [cb]),
  dropStringIndex: [Function] (cname, path, [cb]),
  ensureIStringIndex: [Function] (cname, path, [cb])
                                 Ensure case insensitive String index for JSON field path,
  rebuildIStringIndex: [Function] (cname, path, [cb]),
  dropIStringIndex: [Function] (cname, path, [cb]),
  ensureNumberIndex: [Function] (cname, path, [cb])
                                Ensure index presence of Number type for JSON field path,
  rebuildNumberIndex: [Function] (cname, path, [cb]),
  dropNumberIndex: [Function] (cname, path, [cb]),
  ensureArrayIndex: [Function] (cname, path, [cb])
                                Ensure index presence of Array type for JSON field path,
  rebuildArrayIndex: [Function] (cname, path, [cb]),
  dropArrayIndex: [Function] (cname, path, [cb]),
  getDBMeta: [Function] Get description of EJDB database and its collections,
  beginTransaction: [Function] Begin collection transaction,
  commitTransaction: [Function] Commit collection transaction,
  rollbackTransaction: [Function] Rollback collection transaction,
  getTransactionStatus: [Function] Get collection transaction status }

Then save something:

ejdb>'mycollection', {foo : 'bar'});
[ { foo: 'bar',
    _id: '50d2f2fa7075995500000000' } ]
ejdb>'mycollection', {foo : 'bar2'});
[ { foo: 'bar2',
    _id: '50d2f3007075995500000001' } ]
ejdb>'mycollection', {foo : 'bar3'});
[ { foo: 'bar3',
    _id: '50d2f3037075995500000002' } ]

Show db status and its collections:

ejdb> db.getDBMeta()
{ file: '/home/adam/mydb',
   [ { name: 'mycollection',
       file: '/home/adam/mydb_mycollection',
       records: 3,
        { buckets: 131071,
          cachedrecords: 0,
          large: false,
          compressed: false },
       indexes: [] } ] }

Select first record:

ejdb> db.findOne('mycollection');
{ _id: '50d2f2fa7075995500000000',
  foo: 'bar' }

All records:

var cursor = db.find('mycollection');
Found 3 records
{ _id: '50d2f2fa7075995500000000',
  foo: 'bar' }
{ _id: '50d2f3007075995500000001',
  foo: 'bar2' }
{ _id: '50d2f3037075995500000002',
  foo: 'bar3' }

We can do more with saved cursor object:

ejdb> cursor
{ pos: 0,
  length: 3,
  close: [Function: close],
  reset: [Function: reset],
  hasNext: [Function: hasNext],
  next: [Function: next],
  field: [Function: field],
  object: [Function: object] }
ejdb> while ( console.log("foo" + cursor.field("foo"));

Finish this little demo:

ejdb> db.close();
ejdb> Bye!