我正在尝试使用 MongoDB Compass 1.20.4 连接到 MongoDB
我的连接字符串是:
mongodb://localhost:27017/?replicaSet=rs0
这是我的 MongoDB 泊坞窗设置:
version: '3'
services:
mongo0:
hostname: mongo0
container_name: mongo0
image: mongo
ports:
- 27017:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
mongo1:
hostname: mongo1
container_name: mongo1
image: mongo
ports:
- 27018:27017
restart: always
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
mongosetup:
hostname: mongosetup
container_name: mongosetup
image: mongo
depends_on:
- mongo0
- mongo1
volumes:
- ./scripts/:/scripts
restart: "no"
entrypoint: [ "bash", "/scripts/mongo-setup.sh" ]
mongo-setup.sh
#!/bin/bash
sleep 10
mongo --host mongo0:27017 <<EOF
var config={"_id":"rs0","members":[{"_id":0,"host":"mongo0:27017"},{"_id":1,"host":"mongo1:27017"}]};
rs.initiate(config);
EOF
这是我在 docker 日志中看到的内容:
mongo0 | 2020-02-02T14:42:35.114+0000 I NETWORK [listener] connection accepted from 172.27.0.1:55494 #31 (4 connections now open)
mongo0 | 2020-02-02T14:42:35.115+0000 I NETWORK [conn31] received client metadata from 172.27.0.1:55494 conn31: { driver: { name: "nodejs", version: "3.4.0" }, os: { type: "Darwin", name: "darwin", architecture: "x64", version: "19.3.0" }, platform: "'Node.js v10.2.0, LE (unified)", application: { name: "MongoDB Compass" } }
mongo0 | 2020-02-02T14:42:35.120+0000 I NETWORK [conn31] end connection 172.27.0.1:55494 (3 connections now open)
在使用副本集之前,它连接得很好,Studio 3T 也可以完美地与此设置配合使用。将不胜感激任何帮助