- Hands-On Kubernetes on Windows
- Piotr Tylenda
- 319字
- 2021-06-24 16:54:03
Writing and reading test data
Follow these steps to write and read test data:
- First, in the mongo shell for the ReplicaSet primary node (as a prompt, you will see replSet0:PRIMARY> ), let's add 1,000 sample documents in the demo collection:
for (var i = 1; i <= 1000; i++) {
db.demo.insert( { exampleValue : i } )
}
- You can quickly verify the inserted documents by using the find() method on the demo collection:
db.demo.find()
- Now, we will create a minimalistic .NET Core 3.0 console application running in a Docker container. This will connect to the ReplicaSet running in our Docker container, query our demo collection, and write a value of exampleValue for each document to standard output.
You can find the source code and Dockerfile for this in this book's GitHub repository: https://github.com/PacktPublishing/Hands-On-Kubernetes-on-Windows/tree/master/Chapter02/04_MongoDB_dotnet.
To read our test data, we need to build the application Docker image and create a container that's running in the mongo-cluster network. Perform the following steps to do so:
- Clone the repository and navigate to the Chapter02/04_MongoDB_dotnet directory in PowerShell.
- Execute docker build in the current directory in order to create the mongo-dotnet-sample Docker image:
docker build -t mongo-dotnet-sample:latest .
- Run the sample container. This needs to be connected to the mongo-cluster network:
docker run --isolation=process `
--rm `
--net mongo-cluster `
mongo-dotnet-sample:latest
In the output, you should see an increasing sequence of numbers, which is the values of exampleValue in our test documents:
If you are curious, you can check what the SMB share contains on Azure Portal (https://portal.azure.com/):
Congratulations! You have successfully created and tested a MongoDB ReplicaSet running in a Windows container with Azure Files SMB share being used as a bind mount for storing data. Let's quickly summarize what we have learned in this chapter.
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 機械工程師Python編程:入門、實戰與進階
- JS全書:JavaScript Web前端開發指南
- FLL+WRO樂高機器人競賽教程:機械、巡線與PID
- Python機器學習經典實例
- Windows Forensics Cookbook
- Python編程從0到1(視頻教學版)
- JavaScript應用開發實踐指南
- 從零開始學Python網絡爬蟲
- Mastering Elasticsearch(Second Edition)
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- Angular應用程序開發指南
- Fastdata Processing with Spark
- Python+Office:輕松實現Python辦公自動化
- LabVIEW數據采集