Related
Quick Links
LiteDBis a .NET native NoSQL embedded database.
Built-in .NET, LiteDB is easily accessible to PowerShell and works wonderfully as a local and flexible database.
Built-in encryption, SQL-like commands, and ACID-compliant with full transaction support LiteDB is simple and easy to use.
Additionally, to avoid the need for administrative rights, we are installing this under the
scope.
Next, we are going to import the library for use.
you could simply useAdd-Typeand point to the path of the assembly, but we can automate that.
We will need to define the path where to create the database file.
Since LiteDB creates single file databases, the database can be located anywhere.
In this case, we will locate the DB in our current path and use the name ofTest.db.
Indexes are valuable as they increase performance and allow for easily named queries when searching for a record.
Implemented using skip-lists, indexes avoid a full-scan and deserialization of the database every time a search is done.
Adding a Record Into a LiteDB Collection
First, we need to set up theLiteDB.BSONMapper.
This is LiteDB’s implementation of documents, which stores key-value pairs.
We can also test if the document exists, using theExists()method.
Verify that the document exists, located the specific document, and then all documents.
This is done using the aptly namedUpdate()method.
Of course, we may not want to keep this document.
Therefore, we can remove the document using theRemove()method.
This requires us to know the ID of the document.
Since we already have the information in the$Itemvariable, we can leverage the_idproperty to remove the document.
This is an important step, otherwise, we may end up with corruption.
Explore LiteDB and see what you could do with it today!