当前位置:网站首页>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 ;
边栏推荐
- Try with resource close resource flow
- First blog
- Interviewer: what is an iterator? What is the relationship between async await and iterators?
- How do product managers get started? How do they learn when no one takes them?
- Wind farm visualization: wind farm data
- C language - minesweeping
- 钱堂教育的证券账户安全吗?靠谱吗?
- Interview experience - list of questions
- Ethernet
- SAP ui5 application development tutorial XXIX - Introduction to routing and navigation functions of SAP ui5 trial version
猜你喜欢
Do you know what a three-tier architecture is?
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware

What is the use of the subprocess module

Mirror image of binary tree
Vscode voice notes to enrich information (medium)

Deep analysis of recursion in quick sorting
Use generator-easy-ui5 to quickly create the engineering structure of SAP ui5 applications
Some common errors and solutions of using SAP ui5 to consume OData services

MySQL tuning --01--- optimization steps and system performance parameters

CVPR2021-Semi-supervised Domain Adaptation based on Dual-level Domain Mixing for Semantic Segmentati
随机推荐
ArcGIS Engine + Visual Studio installation tutorial
Go quiz: considerations for function naming return value from the go interview question (more than 80% of people answered wrong)
PIP connects to Tsinghua source by default
SAP ui5 tutorial for beginners part XXVI - detailed steps for using OData service with mock server trial version
[untitled]
The simplest way to tell you is to hash and not hash
An example of recursion, the full permutation problem of 1~n
Monkey test of APP automation
ERDAS 9.2 installation tutorial
2022.1.21 diary
Wind farm visualization: wind farm data
D compile time reflection
3.2.3 use tcpdump to observe TCP header information (supplement common knowledge of TCP protocol)
Technology inventory: past, present and future of Message Oriented Middleware
SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5
[QT] for multithreaded programs, do not use the printf() function to print out
A method of automatic continuation of previous tables in word table
SAP ui5 beginner tutorial 25 - using proxy server to solve the cross domain problem of SAP ui5 application accessing remote OData service trial version
The locally developed SAP ui5 application is deployed to the ABAP server to perform error analysis
MySQL transaction learning notes (I) first encounter