- 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.
- C++程序設計教程
- Redis Applied Design Patterns
- Boost C++ Application Development Cookbook(Second Edition)
- Python應用輕松入門
- 深度強化學習算法與實踐:基于PyTorch的實現(xiàn)
- Oracle從入門到精通(第5版)
- C語言程序設計上機指導與習題解答(第2版)
- HTML5 APP開發(fā)從入門到精通(微課精編版)
- 深度學習:Java語言實現(xiàn)
- C#開發(fā)案例精粹
- Qlik Sense? Cookbook
- RubyMotion iOS Develoment Essentials
- ArcPy and ArcGIS(Second Edition)
- CryENGINE Game Programming with C++,C#,and Lua
- Learning iOS Penetration Testing