Shell - negue/LiteDB GitHub Wiki
LiteDB project has a simple console application that can be used to work with your databases with an application. It's very useful to see, update and test your data. Shell application support all database commands in a similar MongoDB shell syntax.
Shell commands are available in a console application and LiteDatabase
:
using(var db = new LiteDatabase("MyDatabase.db"))
{
db.Run("db.customer.insert { _id:1, Name: \"John Doe\" }");
var col = db.GetCollection("customer");
var john = col.FindById(1);
}
The commands here works only in console application LiteDB.Shell.exe
:
-
help [full]
- Display basic or full commands help -
open <filename>
- Open new database. If not exists, create a new one -
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 -
quit
- Exit shell application
Syntax: db.<collection>.<command>
-
insert <jsonDoc>
- Find a document using query filter syntaxdb.customer.insert { _id:1, Name: "John Doe", Age: 38 }
-
db.customer.insert { Name: "John Doe" }
- Auto create Id asObjectId
-
bulk <filename.json>
- Insert all documents inside a JSON file. JSON file must be an JSON array of documentsdb.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 syntaxdb.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 collectionsdb.customers.indexes
-
dropIndex <field>
- Drop an indexdb.customers.dropIndex Name
-
drop
- Drop a collection and all documents inside. Return false in not existsdb.customer.drop
-
rename
- Rename a collection. Return true if success or false in an error occursdb.customer.rename my_customers
-
count <filter>
- Count documents with defined filter. See<filter>
syntax belowdb.customer.count Name = "John Doe"
- `db.customer.count Age between [20, 40]
-
min <field>
- Get lowest value in field indexdb.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 belowdb.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.
Syntax: fs.<command>
-
upload <fileId> <filename>
- Upload a new local file to database. If fileId exists, override data contentfs.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 metadatafs.update my-file { user: "John", machine: "srv001" }
-
delete <fileId>
- Delete a filefs.delete my-file
-
find [fileId]
- List all files inside database or starting with fileId parameterfs.find
fs.find $/photos/
-
begin
- Begin a new transaction -
commit
- Commit current transaction -
rollback
- Rollback current transaction -
db.info
- Show information about database file