To be clear, the issue I'm seeing is that the above code is trying to cast the BsonValue
as a BsonDocument
....which I don't see how that would ever work. To answer your question:
The BsonDocument
passed to the BsonValue
is created like so:
BsonDocument ToBsonDocument()
{
BsonDocument retVal = new BsonDocument();
retVal["x"] = x;
retVal["y"] = y;
return retVal;
}
System.NotSupportedException: BSON type not supported
BsonMapper.Global.RegisterType<LogEvent>(
serialize: (LogEvent) => new BsonValue(JsonConvert.SerializeObject(LogEvent)),
deserialize: (BsonValue) => JsonConvert.DeserializeObject<LogEvent>(BsonValue.AsString, new LogEventJsonConverter(), new LogEventPropertyValueConverter())
);
LogEvent
to a BsonValue
containing a string. While this is supported (and even useful in some instances), you won't be able to have LogEvent
as the top-level object in a collection, you would only be able to use it as a sub-object.
BsonValue
s like string or int, you can only insert BsonDocument
s in a collection
BsonMapper.Global.RegisterType<LogEvent>(
serialize: (LogEvent) => LiteDB.JsonSerializer.Deserialize(JsonConvert.SerializeObject(LogEvent)),
deserialize: (BsonValue) => JsonConvert.DeserializeObject<LogEvent>(BsonValue.AsDocument.ToString(), new LogEventJsonConverter(), new LogEventPropertyValueConverter())
);
Delete<T>(T Entity, string collectionName)
or DeleteMany<T>(IEnumerable<T> entities, string collectionName)
as input. My class handles passing entities through to the LiteRepository but does not know anything about the entities passed in, so I can not get the id to pass in or to create a predicate. Is there a way to pass in an entity to be deleted?
Need your help on deserializing a List.
i create dynamically a query and get the result like this:
var resultSet = _store.Execute(sql).ToEnumerable().Select(s => BsonMapper.Global.Deserialize<SongData>(s)).ToList();
In my SongData class i have:
public List<string> PictureHashList => _pictureHashList;
Using LiteDBStudio i can see that i have values in the list, but the above query returns an empty list.
Any ideas?
using var _db = new LiteDatabase(_path);
var _dbCol = _db.GetCollection("CollectionName", BsonAutoId.Int32);
$.Properties.customer.Properties[*].FirstName any = 'Jonathan'
. Similarly, if you want to check whether all of these are equal to a value, you can use $.Properties.customer.Properties[*].FirstName all = 'Jonathan'
DateTime
field or even make it your Id field. Due to the BSON spec, LiteDB only stores dates up to the miliseconds (losing a bit of precision). There is a simple workaround for that though, so let me know if you need help with that.
:memory:
as its datafile or by using the LiteDatabase
ctor that takes a Stream (you can pass a MemoryStream
to it)
@raizam You can create an index over a
DateTime
field or even make it your Id field. Due to the BSON spec, LiteDB only stores dates up to the miliseconds (losing a bit of precision). There is a simple workaround for that though, so let me know if you need help with that.
will the DateTime order be preserved when I'll iterate the records? in both indexed/key scenarios?