当前位置:网站首页>C simple operation mongodb
C simple operation mongodb
2022-06-25 05:53:00 【bcbobo21cn】
Create a new form program ; Use Nuget install mongodb.driver; Or directly quote dll as follows ;

Code ;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MongoDB.Bson;
using MongoDB.Driver;
namespace mgtest
{
public partial class Form1 : Form
{
protected static IMongoDatabase _database;
protected static IMongoClient _client;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
const string collectionName = " village ";
string strCon = "mongodb://127.0.0.1:27017/mymgtest";
var mongoUrl = new MongoUrlBuilder(strCon);
string databaseName = mongoUrl.DatabaseName;
_client = new MongoClient(mongoUrl.ToMongoUrl());
_database = _client.GetDatabase(databaseName);
var collection = _database.GetCollection<BsonDocument>(collectionName);
var filter = new BsonDocument();
var list = Task.Run(async () => await collection.Find(filter).ToListAsync()).Result;
list.ForEach(p =>
{
textBox1.Text = textBox1.Text + p["name"].ToString() + "," + p[" The number of "].ToString() + "," + p[" Location "].ToString() + Environment.NewLine;
});
}
}
}Output is as follows ;
This is created earlier mongodb database ;
边栏推荐
- MySQL tuning -- 02 -- slow query log
- BUUCTF(web:1-50)
- Instant messaging project (I)
- Depth of binary tree
- Semantic segmentation cvpr2020 unsupervised intra domain adaptation for semantic segmentation through self supervision
- JSON Library Tutorial from scratch (I): starting to learn and organize notes
- PIP connects to Tsinghua source by default
- How SAP ui5 device type detection device API works
- JMeter stress testing and agent recording
- Common cluster deployment schemes in redis
猜你喜欢

2022.1.25
DOM proficient? What is the difference between node and elment?

Stack and Queue

The simplest way to tell you is to hash and not hash
Introduction to sap ui5 tools

MySQL operation JSON
![[day40 literature extensive reading] space and time in the child's mind: metallic or atomic](/img/98/10b3e63c9609990c51b619d9ca6179.jpg)
[day40 literature extensive reading] space and time in the child's mind: metallic or atomic

C language -- Sanzi chess
Vscode voice notes to enrich information (Part 1)

Only these four instructions are required to operate SQL data
随机推荐
JSON Library Tutorial from scratch (II): parsing digital learning and sorting notes
SAP ui5 date type sap ui. model. type. Analysis of date parsing format
Semantic segmentation cvpr2019-advance: advantageous enterprise minimization for domain adaptation in semantic segmentation
C language - minesweeping
An example of recursion, the full permutation problem of 1~n
SAP ui5 beginner tutorial No. 27 - unit test tool quNit introduction trial version for SAP ui5 application
Technology Review: Interpretation of cloud native architecture trend in 2022
Soft exam information system project manager_ Management Science (Operations Research) -- senior information system project manager of soft test 033
SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications
Understanding of process, thread, task queue, event loop, macro task, micro task, execution stack and other concepts in JS
Semantic segmentation fcns in the wild: pixel level adaptive and constraint based adaptation
Linus' speech recordings, which were lost in 1994, were made public
钱堂教育的证券账户安全吗?靠谱吗?
The simplest way to tell you is to hash and not hash
Folding mobile phones are expected to explode, or help Samsung compete with apple and Chinese mobile phones
Day13 (inner class, anonymous inner class, API common class)
MySQL -- optimize query statements and use not in with cases
ThreadLocal
Deep analysis of epoll reactor code
Jenkins installation and configuration