Example #1
0
        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"));
            }
        }
        /// <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();
            }
        }
Example #3
0
        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"));
                }
        }
Example #4
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var cols = engine.GetCollectionNames().OrderBy(x => x).ToArray();

            if (cols.Length > 0)
            {
                display.WriteLine(ConsoleColor.Cyan, string.Join(Environment.NewLine, cols));
            }
        }
Example #5
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var cols = engine.GetCollectionNames().OrderBy(x => x).ToArray();

            if (cols.Length > 0)
            {
                display.WriteLine(ConsoleColor.Cyan, string.Join(Environment.NewLine, cols));
            }
        }
Example #6
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            if (engine == null)
            {
                display.WriteError("No database file currently open.");
                return;
            }

            var cols = engine.GetCollectionNames().OrderBy(x => x).ToArray();

            if (cols.Length > 0)
            {
                display.WriteLine(ConsoleColor.Cyan, string.Join(Environment.NewLine, cols));
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            var orig = @"C:\Git\LiteDB\LiteDB.Shell\bin\Debug\net40\teste.db";



            using (var db = new LiteEngine(orig))
            {
                var col = db.GetCollectionNames().First();

                var tt = db.FindAll(col).ToArray();

                var c = db.FindOne("DataObjects_1", Query.EQ("_id", "qyeyeW.1oMJK5"));



                Console.WriteLine(c == null);
            }
            //{
            //    // reading all database
            //    foreach (var col in db.GetCollectionNames())
            //    {
            //        Console.WriteLine("Collection: " + col);
            //
            //
            //        foreach (var doc in db.Find(col, Query.All("Token.LastUsedOn")).Take(10))
            //        {
            //            Console.WriteLine(JsonSerializer.Serialize(doc, true));
            //            // ok
            //        }
            //    }
            //}


            Console.WriteLine("End.");
            Console.ReadKey();
        }