2

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.

serdar
  • 23
  • 3

1 Answers1

1

Simple way

var json = JsonSerializer.Serialize(new BsonArray(db.Engine.Find("mycol")));

db.Engine.Insert("mycol", JsonSerializer.Deserialize(json).AsArray.ToArray());
Julien J
  • 2,826
  • 2
  • 25
  • 28
  • Ok, excuse me..I’m really new with programming so I will ask in detail: I got a model inventory and a model users. When a user has a item of inventory it’s not longer available for others... until user gives it back. So my data(Csv) has columns like “description”, “category” “user” etc. Will it work, when I push all columns like this code you post? And the second question: where I must write this code? In cshtml or what:) sorry I’m really new doing this – serdar Feb 01 '20 at 22:07