Search code examples
bsonlitedbnosql

Lite DB not finding inner object query


I have two objects.

 [DataContract]
 public class Record
 {
    [DataMember]
    public string Id { get; set; }
 }

And this class:

public class BatteryStatus : Record
{
    [DataMember]
    public DateTime RetrieveTime { get; set; }

}

I'm using Lite DB as a local NoSQL option to query and save the data. I'm needing to find and delete the values based after some time. Here's my code doing so:

            var col = db.GetCollection<BatteryStatus>(CollectionName);
            var test = col.FindAll()
                .Where(x => x.Id == status.Id).ToList();
            var result = col.Find(Query.EQ("Id", status.Id.ToString())).ToList();

Test returns with the with the object, but the result value doesn't. Lite DB only uses the Query or the BSONId as a way to delete an object. I don't have a BSON id attached to it (it's a referenced definition so I can't change it).

How can I use the "Query" function in order to get a nested value so I can delete it?


Solution

  • I figured out the problem with LiteDB, since I was using the property name of "Id", the BSON interpreted that as the "_id" of the JSON object, and merging their two values. I solve the issue by renaming the "Id" property to something else.