Litedb: Error updating value on unity3d

Created on 11 May 2017  路  4Comments  路  Source: mbdavid/LiteDB

hello again, here is my issue:

LiteException: Invalid BSON data type 'Null' on field '_id'.
LiteDB.LiteEngine.UpdateDocument (LiteDB.CollectionPage col, LiteDB.BsonDocument doc)
LiteDB.LiteEngine+<>c__DisplayClass61_0.<Update>b__0 (LiteDB.CollectionPage col)
LiteDB.LiteEngine.Transaction[Int32] (System.String collection, Boolean addIfNotExists, System.Func`2 action)
UnityEngine.EventSystems.EventSystem:Update()

my code that gives this error:

var statRes = collectionStats.Find(x => x.name == name);
if (statRes.Count<dtStats>() > 0)
{
    // found: update
    var upd = statRes.First<dtStats>();

    upd.value_float = Convert.ToSingle(value);
    collectionStats.Update(upd);
}

and my class is this:

public class dtStats
{
    [BsonIndex(true)]
    public string name { get; set; }
    public string value_string { get; set; }
    public float? value_float { get; set; }
    public int? value_int { get; set; }
}

All 4 comments

I have had problems using update with unity branch too, I found that Upsert worked in the case it failed. Update is now working again for me although I am using a table with [BsonId(false)]

one other thing I found along the way is that it doesn't like null strings either, so I make sure these are empty strings

thanks @mcintyrg I've solved using this class:

    public class dtStats
    {
        [BsonId]
        public int PK { get; set; }
        public string name { get; set; }
        public string value_string { get; set; }
        public float value_float { get; set; }
        public int value_int { get; set; }
    }

Hi! With the objective of organizing our issues, we are closing old unsolved issues. Please check the latest version of LiteDB and open a new issue if your problem/question/suggestion still applies. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

muhamad picture muhamad  路  3Comments

rstat1 picture rstat1  路  3Comments

MoamenMohamed picture MoamenMohamed  路  4Comments

furesoft picture furesoft  路  4Comments

LiamKenneth picture LiamKenneth  路  3Comments