LITEDB - A .NET NOSQL DOCUMENT STORE IN A SINGLE DATA FILE Larry Nung
AGENDA Introduction Installation How to use Reference Q & A 2
INTRODUCTION 3
INTRODUCTION 4
INSTALLATION 5
INSTALLATION  Install-Package LiteDB 6
HOW TO USE 7
OPEN FILE DB 8 … using (var db = new LiteDatabase(dbFile)) { ... }
OPEN NEMORY DB 9 … using (var ms = new MemoryStream(buffer)) using (var db = new LiteDatabase(ms)) { ... }
GET COLLECTION 10 … using (var db = new LiteDatabase(dbFile)) { var collection = db.GetCollection<T>(collectionName); ... }
INSERT DATA 11 … using (var db = new LiteDatabase(dbFile)) { var collection = db.GetCollection<T>(collectionName); var collectionItem = new T(); collection.Insert(collectionItem); }
BATCH INSERT DATA 12 … using (var db = new LiteDatabase(dbFile)) { var collection = db.GetCollection<T>(collectionName); collection.InsertBulk(data, batchSize); }
UPDATE DATA 13 … using (var db = new LiteDatabase(dbFile)) { var collection = db.GetCollection<T>(collectionName); var collectionItem.Property = newValue; collection.Update(collectionItem); }
QUERY DATA … using (var db = new LiteDatabase(dbFile)) { var collection = db.GetCollection<T>(collectionName); foreach (var collectionItem in collection.Find(item => item.Property == value)) { … } } 14
QUERY ALL DATA … using (var db = new LiteDatabase(dbFile)) { var collection = db.GetCollection<T>(collectionName); foreach (var collectionItem in collection.FindAll()) { … } } 15
SET PROPERTY INDEX … using (var db = new LiteDatabase(dbFile)) { var collection = db.GetCollection<T>(collectionName); ... collection.EnsureIndex(item => item.Property); } 16
UPLOAD FILE … using (var db = new LiteDatabase(dbFile)) { db.FileStorage.Upload(id, file); } 17
OPEN FILE … using (var db = new LiteDatabase(dbFile)) { … using (var stream = db.FileStorage.OpenRead(id)) { … } } 18
DOWNLOAD FILE … using (var db = new LiteDatabase(dbFile)) { … using(var fileStream = File.Create(id)) { fs.Download(id, fileStream); } } 19
REFERENCE 20
REFERENCE  LiteDB :: A .NET embedded NoSQL database  http://www.litedb.org/ 21
Q&A 22
QUESTION & ANSWER 23

LiteDB - A .NET NoSQL Document Store in a single data file