question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need Help: Reading from Json an inserting to collection

See original GitHub issue

Hi, Im getting the following error while trying to read from json and inserting into Db below is code:

            openLoadDef.FileName = "";
            openLoadDef.ShowDialog();
            string errordef = openLoadDef.FileName;
            List<BsonDocument> docs = new List<BsonDocument>();
            StreamReader r = new StreamReader(errordef);
            var json = r.ReadToEnd();
            var jsonObj = JsonSerializer.Deserialize(json);
            docs = BsonMapper.Global.ToDocument(jsonObj);
            using (var db = new LiteDatabase("ErrorMsg.db"))
            {
                db.GetCollection("ErrorMsg").InsertBulk(docs);
            }

I’m getting the error at BsonMapper Cannot implicitly convert type ‘LiteDB.BsonDocument’ to System.Collections.Generic.List<LiteDB.BsonDocument>’

Can you please advise whats needs to be changed. Input is a plain json file.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mbdavidcommented, Jul 1, 2018
  1. Yes, add this [ ] to create an single array bson value
  2. You don’t need BsonMapper, you are using BsonDocument type (and not a POCO class)
  3. Just transform your array into IEnumerable of documents:
var docs = JsonSerializer.DeserializeArray(jsonArrayAsString).Select(x => x.AsDocument);
db.GetCollection("ErrorMsg").InsertBulk(docs);
0reactions
lbnascimentocommented, Feb 28, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create collections dynamically and insert json file's ...
I have been looking on how to create collections dynamically such that each collection say a_col has a.json data inserted, b_col has b.json...
Read more >
How to Read JSON Data and Insert It Into a Database
From within the Project Designer page, expand the Data Translation folder in the Component Library, and then drag the Read JSON task to...
Read more >
Import JSON data into SQL Server
This article explores the process of JSON data import in SQL Server table using T-SQL and SSIS.
Read more >
How to read a .json file and insert the data into a SharePoint list?
Solved: Hello I want to create a flow that reads a .json file and inserts the data into a SharePoint list. Each data...
Read more >
JSON to MongoDB Python: Operations Simplified 101 - Learn
In this article, you will learn about how to insert data from JSON to MongoDB Python. Also, learn to perform operations and import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found