LiteDB索引大小限制问题

时间:2016-03-09 12:01:11

标签: c# indexing nosql

我使用此代码将项目插入数据库:

using (var db = new LiteDatabase(dataFilePath))
{
    LiteCollection<DbEntry> collection = db.GetCollection<DbEntry>("stuff");
    collection.InsertBulk(sourceEntries.Select(Mapper.Map<DbEntry>));
}

我收到此错误:

LiteDB.LiteException: Index key must be less than 512 bytes
   at LiteDB.IndexService.AddNode(CollectionIndex index, BsonValue key, Byte level)
   at LiteDB.LiteCollection`1.Insert(T document)
   at LiteDB.LiteCollection`1.InsertBulk(IEnumerable`1 docs, Int32 buffer)

我认为我根本没有弄乱任何索引,但如果有办法检查它,请告诉我。

DbEntry看起来有点像(没有明确的标识符):

public class DbEntry
{
    public string Message { get; set; }
    public string Source { get; set; }
}

dataFilePath每天都不同,有时它可以容纳200MB的数据,当文件有大约1.5MB的数据时,就会出现此错误。

1 个答案:

答案 0 :(得分:0)

不熟悉LiteDB,但建议:

您没有指定您使用的版本。它已经稳定1.4或2.0了吗? 1.4中的每个条目都有(1?)的限制为1 MB。看一下将项目存储为文件。

我还要通过命名字段_id或通过[BsonId]明确设置条目ID。也许LiteDB将整行用作ID,并在尝试索引表时阻塞它。

相关问题