当前位置:网站首页>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 ;
边栏推荐
- Get the first letter of Chinese phonetic alphabet in Excel and capitalize it
- What is the use of the subprocess module
- CST8227
- SAP ui5 beginner tutorial No. 27 - unit test tool quNit introduction trial version for SAP ui5 application
- SAP ui5 application development tutorial XXIX - Introduction to routing and navigation functions of SAP ui5 trial version
- ArcGIS Engine + Visual Studio installation tutorial
- Voxel based and second network learning
- Ethernet
- SAP ui5 date type sap ui. model. type. Analysis of date parsing format
- Pytorch- daily learning notes of some small functions involving training
猜你喜欢

Solve some prompt codes that pychar cannot recognize selenium
Go language map sorting (key/value sorting)
Yunda's cloud based business in Taiwan construction 𞓜 practical school

Design of IM login server and message server

Synchonized introduction

2022.1.21 diary

What is the use of the subprocess module

Trouble of setting table property to null
SAP ui5 application development tutorial 32 - how to create a custom SAP ui5 control

Mirror image of binary tree
随机推荐
CVPR2021-Semi-supervised Domain Adaptation based on Dual-level Domain Mixing for Semantic Segmentati
Design of IM login server and message server
Learn the interface test, see it is very good, and make a note
Only these four instructions are required to operate SQL data
How to add an external header file in vs?
3.2.3 use tcpdump to observe TCP header information (supplement common knowledge of TCP protocol)
Trouble of setting table property to null
钱堂教育的证券账户安全吗?靠谱吗?
Pytorch- daily learning notes of some small functions involving training
CSDN cerebral palsy bug has wasted nearly two hours of hard work
Common cluster deployment schemes in redis
Which securities company is good for opening a mobile account? Is it safe to open a mobile account?
16 application problem solving
About the definition of pointer variables (personal notes)
Go quiz: considerations for function naming return value from the go interview question (more than 80% of people answered wrong)
Linus' speech recordings, which were lost in 1994, were made public
Code learning-cvpr2020 unsupervised domain adaptive semantic segmentation: intra advance
[untitled]
Vscode voice notes to enrich information (Part 1)
Kubevela v1.2 release: the graphical operation console velaux you want is finally here!