0

I have a mongo replicaset container and a mongo client container.

When I try to connect from the mongo shell client, it can connect but at first command it stops and exit without error message ?! Other "non shell client" do not have that issue. No lock file found. Any idea ?

root@mongoclient-b8b6c4cff-2k5hg:~# mongo mongodb://root:xxx@mongodb:27017/db?authSource=admin&replicaSet=rs0
[12] 401
root@mongoclient-b8b6c4cff-2k5hg:~# MongoDB shell version v4.0.6
connecting to: mongodb://mongodb:27017/db?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5b6daf02-fc3b-4995-9819-728810c9011a") }
MongoDB server version: 4.0.3
Server has startup warnings: 
2019-02-22T09:12:54.186+0000 I STORAGE  [initandlisten] 
2019-02-22T09:12:54.186+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-02-22T09:12:54.186+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-02-22T09:12:55.199+0000 W CONTROL  [initandlisten] 
2019-02-22T09:12:55.199+0000 W CONTROL  [initandlisten] 
2019-02-22T09:12:55.199+0000 I CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---



[12]+  Stopped                 mongo mongodb://root:xxx@mongodb:27017/db?authSource=admin
root@mongoclient-b8b6c4cff-2k5hg:~#  
phico
  • 1,303
  • 11
  • 12
  • Related: [How to execute mongo commands through shell scripts?](https://stackoverflow.com/q/4837673/2313887) – Neil Lunn Mar 02 '19 at 04:03

2 Answers2

3

This happens because & is a special character in the shell, and you have one unescaped in your URL.

You can simply quote the URL so that the shell doesn't try to interpret it:

mongo "mongodb://root:xxx@mongodb:27017/db?authSource=admin&replicaSet=rs0"
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • can you please help this question https://stackoverflow.com/questions/54944193/how-to-merge-csv-files-onto-a-single-file-on-condition-and-adding-file-name-as-a – panda Mar 02 '19 at 06:31
0

Well .. I found the solution, it turns out that removing the replicaset parameter in the url works !?

phico
  • 1,303
  • 11
  • 12
  • 1
    It "works", but it also disables your "replicaSet" connection, so you would only be connecting to a **single node** without it. For the real reason and fix, [do what the other person who answered told you.](https://stackoverflow.com/a/54950785/2313887) – Neil Lunn Mar 02 '19 at 04:01