简体   繁体   中英

How Can I Insert Data to Mongodb From String in Dotnet Core

I am newbie in dotnet and mongodb world.I am fetching a json string form an api and i want to insert them to mongodb.Assume that we have this string:

string json = "{'a': '5e7629e5ca467a22e9464c6f'},{'a': '5e7629e5744c85ffb94de085'}";

This string contains 2 document in my view.I want to insert mongodb as 2 document.But if i try to insert them like this:

collection.InsertOne(json);

it is inserting as 1 document all of them. I think should serialize the string then insert documents one by one.

How can i achieve insert string to MongoDB as multiple documents?

Use BsonDocument.Parse(your_json_string) . Then you will be able using collection.InsertMany..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM