/// <summary> /// Read all colleciton, indexes and documents inside current datafile /// Drop per index, per collection and shrink /// This steps will check/validate all file data /// </summary> private void CheckIntegrity() { using (var db = new LiteEngine(this.Filename)) { var cols = db.GetCollectionNames().ToArray(); foreach (var col in cols) { var indexes = db.GetIndexes(col).ToArray(); foreach (var idx in indexes) { var q = db.Find(col, Query.All(idx.Field)); foreach (var doc in q) { // document are ok! } // lets drop this index (if not _id) if (idx.Field != "_id") { db.DropIndex(col, idx.Field); } } // and drop collection db.DropCollection(col); } // and now shrink db.Shrink(); } }
public void DropCollection_Test() { using (var file = new TempFile()) using (var db = new LiteEngine(file.Filename)) { Assert.IsFalse(db.GetCollectionNames().Any(x => x == "col")); db.Insert("col", new BsonDocument { { "a", 1 } }); Assert.IsTrue(db.GetCollectionNames().Any(x => x == "col")); db.DropCollection("col"); Assert.IsFalse(db.GetCollectionNames().Any(x => x == "col")); } }
public void DropCollection() { using (var file = new TempFile()) using (var db = new LiteEngine(file.Filename)) { Assert.IsFalse(db.GetCollectionNames().Any(x => x == "col")); db.Insert("col", new BsonDocument { { "a", 1 } }); Assert.IsTrue(db.GetCollectionNames().Any(x => x == "col")); db.DropCollection("col"); Assert.IsFalse(db.GetCollectionNames().Any(x => x == "col")); } }
public void Shrink_After_DropCollection() { using (var file = new TempFile()) using (var db = new LiteEngine(file.Filename)) { db.InsertBulk("col", GetDocs(1, 10000)); db.DropCollection("col"); // full disk usage var size = file.Size; var r = db.Shrink(); // only header page + reserved lock page Assert.AreEqual(8192, size - r); } }
public void Drop() { _db.DropCollection("col_bulk"); }
public IEnumerable <BsonValue> Execute(StringScanner s, LiteEngine engine) { var col = this.ReadCollection(engine, s); yield return(engine.DropCollection(col)); }
public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env) { var col = this.ReadCollection(engine, s); display.WriteResult(engine.DropCollection(col)); }