csvopencsvlitedb

LiteDB import a csv


I don’t know how I can import a Csv to LiteDB. I searched a lot but don’t get a solution. I’m using asp.net core 3.1 razor pages to build a one page website and I store my data in LiteDB. Now I have data to import, but I don’t know how.


Solution

  • Simple way

    var json = JsonSerializer.Serialize(new BsonArray(db.Engine.Find("mycol")));
    
    db.Engine.Insert("mycol", JsonSerializer.Deserialize(json).AsArray.ToArray());