Skip to content
yaras edited this page Apr 18, 2017 · 16 revisions

LiteDB project has a simple console application (LiteDB.Shell.exe) that can be used to work with your databases. It's very useful to see, update and test your data. Shell tool use a disconnected instance of LiteEngine, so each command connect (in read only if you are only quering) and execute your command and disconnect.

Reference

Shell console commands

The commands here works only in console application LiteDB.Shell.exe:

  • help [full] - Display basic or full commands help
  • open <filename|connectionString> - Open new database. If not exists, create a new one. Can be passed a connection string with all options (like password or timeout)
  • close - Close current database
  • pretty - Show JSON in pretty format
  • ed - Open notepad.exe with last command to edit
  • run <filename> - Read filename and add each line as a new command
  • spool [on|off] - Turn on/off spool of all commands
  • timer - Show a timer on command prompt
  • -- - Comments (ignore rest of line)
  • /<command>/ - Supports multiline command
  • upgrade /<filename|connectionString>/ - Upgrade datafile from LiteDB v2
  • version - Show LiteDB assembly version
  • quit - Exit shell application

Collections commands

Syntax: db.<collection>.<command>

  • insert <jsonDoc> - Find a document using query filter syntax

    • db.customer.insert { _id:1, Name: "John Doe", Age: 38 }
    • db.customer.insert { Name: "John Doe" } - Auto create Id as ObjectId
  • bulk <filename.json> - Insert all documents inside a JSON file. JSON file must be an JSON array of documents

    • db.customer.bulk my-documents.json
  • update <jsonDoc> - Update a existing document using _id

    • db.customer.update { _id:1, Name: "Joana Doe", Age: 29 }
  • delete <filter> - Delete documents using filter syntax

    • db.customer.delete _id = 1
    • db.customer.delete Name like "Jo"
  • ensureIndex <field> [true|<jsonOptions>] - Create a new index on collection in field. Support json options See Indexes

    • db.customers.ensureIndex Name true - Create a unique index
    • db.customers.ensureIndex Name { unique: true, removeAccents: false }
  • indexes - List all indexes on collections

    • db.customers.indexes
  • dropIndex <field> - Drop an index

    • db.customers.dropIndex Name
  • drop - Drop a collection and all documents inside. Return false in not exists

    • db.customer.drop
  • rename - Rename a collection. Return true if success or false in an error occurs

    • db.customer.rename my_customers
  • count <filter> - Count documents with defined filter. See <filter> syntax below

    • db.customer.count Name = "John Doe"
    • db.customer.count Age between [20, 40]
  • min <field> - Get lowest value in field index

    • db.customer.min _id
    • db.customer.min Age
  • max <field> -

    • db.customer.max _id
    • db.customer.max Age
  • find [filter][skip N][limit M] - Find documents using query filter syntax. See <filter> syntax below

    • db.customer.find
    • db.customer.find limit 10
    • db.customer.find Name = "John Doe"
    • db.customer.find Age between [20, 40]
    • db.customer.find Name LIKE "John" and Age > 30
  • <filter> = <field> [=|>|>=|<|<=|!=|like|contains|in|between] <jsonValue>

  • <filter> = <filter> [and|or] <filter>

  • <jsonDoc> and <jsonValue> are JSON extended format. See Data Structure.

FileStorage

Syntax: fs.<command>

  • upload <fileId> <filename> - Upload a new local file to database. If fileId exists, override data content

    • fs.upload my-file picture.jpg
    • fs.upload $/photos/pic-001 C:\Temp\mypictures\picture-1.jpg
  • download <fileId> <filename> - Download existing database file to a local file.

    • fs.download my-file copy-picture.jpg
    • fs.download $/photos/pic-001 C:\Temp\mypictures\copy-picture-1.jpg
  • update <fileId> <jsonDoc> - Update file metadata

    • fs.update my-file { user: "John", machine: "srv001" }
  • delete <fileId> - Delete a file

    • fs.delete my-file
  • find [fileId] - List all files inside database or starting with fileId parameter

    • fs.find
    • fs.find $/photos/

Database utils

Syntax: db.<command>

  • userversion [N] - Get/Set user database file version

  • shrink [password] - Reduce database removing empty pages and change password (optional). If password was not provide, new datafile will be not encrypted.

Clone this wiki locally