-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Shell
This documentation is valid only for
v4.x
version.
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.
In v4, LiteDB back shell command support into LiteDB.dll
, so now shell commands are part of LiteDB (not only an external tool).
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
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 }
-
update <field|path>=<value|expression>, [..] [where <filter>]
- Update multiple documents fields using filter querydb.customer.update Name = "John" where _id = 1
db.customer.update Age = $.Age + 1 where _id > 0
db.customer.update Addresses[*].Full = Addresses[*].Street + ", " + Addresses[*].Number
-
delete <filter>
- Delete documents using filter syntaxdb.customer.delete _id = 1
db.customer.delete Name like "Jo"
-
ensureIndex <field|name> [unique] [using <expr>]
- Create a new index on collection in field. Support json options See Indexes-
db.customers.ensureIndex Name unique
- Create a unique index db.customers.ensureIndex NameLower using LOWER($.Name)
-
-
indexes
- List all indexes on collectionsdb.customers.indexes
-
dropIndex <field|name>
- Drop an indexdb.customers.dropIndex Name
-
drop
- Drop a collection and all documents inside. Return false if not existsdb.customer.drop
-
rename
- Rename a collection. Return true if success or false if 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][includes p0, p1, ..]
- 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
db.customer.find skip 10 limit 10 includes $.Orders[*]
-
select [path|expr] as Name1, [path|expr] [where <filter>][skip N][limit M][include p0, p1, ..]
- Find and transform documentsdb.customer.select $ where Age > 30
db.customer.select LOWER($.Addresses[*].Street) where Age > 30
db.customer.select $.Name as Name, ARRAY($.Addresses[@.City = 'NY']) as addresses where 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/
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 provided, new datafile will be not encrypted.
Data Modeling
- Data Structure
- BsonDocument
- Object Mapping
- Relationships with Document References
- Collections
- FileStorage
Index
Query
Database
Version 4 changes
Shell