Import/Export database data

Export or import of the database data can be done by using ejdbcommand API function in language binding of your choice.

C API

bson* ejdbcommand(EJDB *jb, bson *cmdbson)

Execute the ejdb database command

Parameters:
Returns:

Allocated command response BSON object. Caller should call bson_del() on it.

Export command spec

{
    'export': {
        path: '<Export files target directory>',
        cnames: [], //List of collection names to export
        mode: 0 //Export mode
    }
}

Export mode is an integer flag describes the following options:

  • 0: Database collections will be exported as BSON documents (Default).
  • JBJSONEXPORT: Database collections will be exported as JSON files.

Import command spec

{
    'import': {
        path: '<Import files source directory>'
        cnames: [], //List of collection names to import
        mode: 0 //Import mode
    }
}

Import mode is an integer flag describes the following options:

  • 0 or JBIMPORTUPDATE: Update existing collection entries with imported ones.
    Missing collections will be created.
  • JBIMPORTREPLACE: Recreate all collections and replace all collection data with imported entries.
    Missing collections will be created.

Command response

{
    log: '<Command execution diagnostic log>',
    error: '<Error message>',
    errorCode: 0 //Error code number
}