mkdir /mongo-db
cat docker-compose.yaml
version: '3.3'
services:
mongo-db:
image: mongo:4.0.5
hostname: mongo-db
container_name: mongo-db
expose:
- "27017"
ports:
- "27017:27017"
command: --bind_ip_all --smallfiles
volumes:
- ./mongo-db:/data
mongoclient:
image: mongoclient/mongoclient:2.2.0
container_name: mongoclient
hostname: mongoclient
depends_on:
- mongo-db
ports:
- 3000:3000
environment:
MONGO_URL: "mongodb://mongo-db:27017"
PORT: 3000
expose:
- "3000"
Plugin MongoDB:
https://www.confluent.io/hub/mongodb/kafka-connect-mongodb
docker exec -it mongo-db bash
mongo
show datatabase trong mongodbshow dbs
tạo database mới:use todo
Giờ tạo collection and document
> db.newtodo.insertOne({"name": "Nimtechnology", age:2, past_clubs: ["Istio", "Kafka-connect", "K8s"], "isRetired": false})
Tạo xong mà báo như dưới là ok đã tạo thành công.
{
"acknowledged" : true,
"insertedId" : ObjectId("621340e947a838658186b5f5")
}
Liệt kê các document trong collection newtodo
db.newtodo.find()
Để json trong đẹp hơn thì gõ:db.newtodo.find().pretty()
WARN Failed to resume change stream: The $changeStream stage is only supported on replica sets 40573