JosefNemec / LiteDbExplorer

Viewer and editor for https://github.com/mbdavid/LiteDB databases.
MIT License
218 stars 104 forks source link

Cannot delete certain indexed DateTime entries #14

Closed MolecularDust closed 7 years ago

MolecularDust commented 7 years ago

I have a simple test database generated by the following code. The problem is that when I delete all 4 records in LiteDbExplorer and then click "Refresh" button the last two reappear. For some reason the fields generated by DateTime.Now cannot be deleted.

public class LogSample
    {
        [BsonId]
        public DateTime Time { get; set; }
        public string Notes { get; set; }
    }

class Program
    {
        static void Main(string[] args)
        {
            using (var db = new LiteDatabase("Test.db"))
            {
                var collection = db.GetCollection<LogSample>("TestCollection");

                collection.Insert(new LogSample { Time = new DateTime(2017, 1, 1), Notes = "Note 1" });
                collection.Insert(new LogSample { Time = DateTime.Today, Notes = "Note 2" });
                collection.Insert(new LogSample { Time = DateTime.Now, Notes = "Note 3" });
                collection.Insert(new LogSample { Time = DateTime.Now.AddDays(-1), Notes = "Note 4" });

                var allEntries = collection.FindAll();
                foreach (var entry in allEntries)
                {
                    Console.WriteLine("Log entry: " + entry.Time + " " + entry.Notes);
                }
                Console.ReadKey();
            }
        }
    }
JosefNemec commented 7 years ago

I'm unable to reproduce it. Could you please share database file causing the issue? Thanks

JosefNemec commented 7 years ago

Finally got more time to investigate this and it seems like LiteDB issue. When you call Delete method from LiteCollection on those items, it simply won't remove the records and return false. Nothing I can do about that I'm afraid, you should create issue in LiteDB's repository.