I have my local MongoDB running using docker-compose file.
Docker-compose.yml
version: "3.8"
services:
mongodb1:
hostname: mongo1
image: mongo
ports:
- 30001:27017
restart: always
entrypoint:
[
"/usr/bin/mongod",
"--bind_ip_all",
"--dbpath",
"/data/db",
]
volumes:
- ./mongo:/data/db
I am able to connect to it using my app with Mongoose or using mongosh tool:
mongosh --port 30001
Current Mongosh Log ID: 656eec32c328d0a1b0bb20a0
Connecting to: **mongodb://127.0.0.1:30001/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.0**
Using MongoDB: 7.0.2
**Using Mongosh**: 2.1.0
For mongosh info see: **https://docs.mongodb.com/mongodb-shell/**
**------**
**The server generated these startup warnings when booting**
2023-12-05T08:43:37.442+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2023-12-05T08:43:39.030+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2023-12-05T08:43:39.030+00:00: You are running this process as the root user, which is not recommended
2023-12-05T08:43:39.031+00:00: vm.max_map_count is too low
**------**
But ! For some reason, I can not use mongoimport to import data to that same database. I get the following error:
mongoimport -d main -c users ./users.json --port 30001
2023-12-05T09:16:39.411+0000 [........................] adscan-prod.users 0B/7.05KB (0.0%)
2023-12-05T09:16:39.919+0000 [........................] adscan-prod.users 0B/7.05KB (0.0%)
2023-12-05T09:16:39.920+0000 Failed: error connecting to db server: no reachable servers
2023-12-05T09:16:39.920+0000 imported 0 documents
What may be the reason mongoimport is not working? How can I import my data into dockerized mongodb?