public void Query_Test() { using (var file = new TempFile()) using (var db = new LiteEngine(file.Filename)) { db.Insert("col", new BsonDocument[] { new BsonDocument { { "_id", 1 }, { "name", "e" } }, new BsonDocument { { "_id", 2 }, { "name", "d" } }, new BsonDocument { { "_id", 3 }, { "name", "c" } }, new BsonDocument { { "_id", 4 }, { "name", "b" } }, new BsonDocument { { "_id", 5 }, { "name", "a" } } }); db.EnsureIndex("col", "name"); Func <Query, string> result = (q) => string.Join(",", db.FindIndex("col", q).Select(x => x.ToString())); Assert.AreEqual("1", result(Query.EQ("_id", 1))); Assert.AreEqual("4,5", result(Query.GTE("_id", 4))); Assert.AreEqual("1", result(Query.LT("_id", 2))); Assert.AreEqual("a,b,d,e", result(Query.Not("name", "c"))); Assert.AreEqual("2,4", result(Query.Where("_id", (v) => v.AsInt32 % 2 == 0))); } }
public void Find_Index_Keys() { using (var db = new LiteEngine(new MemoryStream())) { db.Insert("col", new BsonDocument { { "Number", 1 } }, BsonType.Int32); db.Insert("col", new BsonDocument { { "Number", 2 } }, BsonType.Int32); db.Insert("col", new BsonDocument { { "Number", 3 } }, BsonType.Int32); db.Insert("col", new BsonDocument { { "Number", 4 } }, BsonType.Int32); db.Insert("col", new BsonDocument { { "Number", 5 } }, BsonType.Int32); db.EnsureIndex("col", "Number"); Assert.AreEqual(5, db.FindIndex("col", Query.EQ("Number", 5)).First().AsInt32); } }
public void MultiKey_InsertUpdate_Test() { using (var file = new TempFile()) using (var db = new LiteEngine(file.Filename)) { db.Insert("col", GetDocs(1, 1, 1, 2, 3)); db.Insert("col", GetDocs(2, 2, 2, 2, 4)); db.Insert("col", GetDocs(3, 3, 3)); // create index afer documents are in collection db.EnsureIndex("col", "list"); db.EnsureIndex("col", "rnd"); db.Update("col", GetDocs(2, 2, 9, 9)); // try find var r = string.Join(",", db.Find("col", Query.EQ("list", 2)).Select(x => x["_id"].ToString())); Assert.AreEqual("1", r); Assert.AreEqual(3, db.Count("col", null)); Assert.AreEqual(3, db.Count("col", Query.All())); // 5 keys = [1, 2, 3],[3],[9] var l = string.Join(",", db.FindIndex("col", Query.All("list"))); Assert.AreEqual("1,2,3,3,9", l); // count should be count only documents - not index nodes Assert.AreEqual(3, db.Count("col", Query.All("list"))); } }
public void Query_Test() { using (var file = new TempFile()) using (var db = new LiteEngine(file.Filename)) { db.Insert("col", new BsonDocument[] { new BsonDocument { { "_id", 1 }, { "name", "e" } }, new BsonDocument { { "_id", 2 }, { "name", "d" } }, new BsonDocument { { "_id", 3 }, { "name", "c" } }, new BsonDocument { { "_id", 4 }, { "name", "b" } }, new BsonDocument { { "_id", 5 }, { "name", "a" } } }); db.EnsureIndex("col", "name"); Func<Query, string> result = (q) => string.Join(",", db.FindIndex("col", q).Select(x => x.ToString())); Assert.AreEqual("1", result(Query.EQ("_id", 1))); Assert.AreEqual("4,5", result(Query.GTE("_id", 4))); Assert.AreEqual("1", result(Query.LT("_id", 2))); Assert.AreEqual("a,b,d,e", result(Query.Not("name", "c"))); Assert.AreEqual("2,4", result(Query.Where("_id", (v) => v.AsInt32 % 2 == 0))); } }