It's hard to follow up the instructions from m312 Hostnames and Cluster Configuration Part_1

Hi folks,

After I followed the guide until " rs.initiate" I got some errors as follows. Any information and advice are appreciated. Thank you guys!

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>vagrant status
Current machine states:

m1                        running (virtualbox)
m2                        running (virtualbox)
m3                        running (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>vagrant ssh m1 -- -t 'mongod -f /shared/mongod.cnf'
about to fork child process, waiting until server is ready for connections.
forked process: 13483
child process started successfully, parent exiting
Connection to 127.0.0.1 closed.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>mongo --host 192.168.15.101 --eval '  rs.initiate({    "_id": "M312",    "members": [      {"_id": 0, "host": "192.168.15.101"},      {"_id": 1, "host": "m2.university.mongodb"},      {"_id": 2, "host": "m3"},    ]  })'
MongoDB shell version v4.2.2
2020-04-28T11:40:40.722-0700 F  -        [main] exception: Database name cannot have reserved characters for mongodb:// URL: mongodb://192.168.15.101:27017/rs.initiate%28%7B
2020-04-28T11:40:40.723-0700 E  -        [main] exiting with code 1

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>mongo --host 192.168.15.101 --eval '  rs.initiate({    "_id": "M312",    "members": [      {"_id": 0, "host": "192.168.15.101"},      {"_id": 1, "host": "m2.university.mongodb"},      {"_id": 2, "host": "m3"},    ]  })'
MongoDB shell version v4.2.2
2020-04-28T11:42:32.342-0700 F  -        [main] exception: Database name cannot have reserved characters for mongodb:// URL: mongodb://192.168.15.101:27017/rs.initiate%28%7B
2020-04-28T11:42:32.342-0700 E  -        [main] exiting with code 1

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>mongo --host 192.168.15.101 --eval '  rs.initiate({    "_id": "M312",    "members": [      {"_id": 0, "host": "192.168.15.101"},      {"_id": 1, "host": "m2.university.mongodb"},      {"_id": 2, "host": "m3"},    ]  })'
MongoDB shell version v4.2.2
2020-04-28T11:44:32.291-0700 F  -        [main] exception: Database name cannot have reserved characters for mongodb:// URL: mongodb://192.168.15.101:27017/rs.initiate%28%7B
2020-04-28T11:44:32.291-0700 E  -        [main] exiting with code 1

I think syntax error
You have additional comma after host m3 and before closinng bracket ]
Please remove it and try again

1 Like

In addition, it’s much easier to just copy the commands as-is instead of typing it out to avoid these unforced errors.

@007_jb Thank you guys! Actually I did copy it from the handouts and I did notice the additional comma . I thought the matter not to be there. But I have tried it again. Unfortunately it doesn’t matter either.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>vagrant status
Current machine states:

m1                        running (virtualbox)
m2                        running (virtualbox)
m3                        running (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>
C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>vagrant ssh m1 -- -t 'mongod -f /shared/mongod.cnf'

about to fork child process, waiting until server is ready for connections.
forked process: 13204
child process started successfully, parent exiting
Connection to 127.0.0.1 closed.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>mongo --host 192.168.15.101 --eval '  rs.initiate({    "_id": "M312",    "members": [      {"_id": 0, "host": "192.168.15.101"},      {"_id": 1, "host": "m2.university.mongodb"},      {"_id": 2, "host": "m3"}    ]  })'
MongoDB shell version v4.2.2
2020-04-29T08:42:42.812-0700 F  -        [main] exception: Database name cannot have reserved characters for mongodb:// URL: mongodb://192.168.15.101:27017/rs.initiate%28%7B
2020-04-29T08:42:42.813-0700 E  -        [main] exiting with code 1



The problem here is, most of the syntax used in the bash script work best in a similar Linux environment, and not Windows.

This should work:

mongo --host 192.168.15.101 --eval "rs.initiate({'_id': 'M312', 'members': [{'_id': 0, 'host': '192.168.15.101'}, {'_id': 1, 'host': 'm2.university.mongodb'}, {'_id': 2, 'host': 'm3'}]})"

In order to make the other lines work in the Windows terminal, follow these guidelines:

  1. Write the command in one line
  2. For --eval ' ':
    • change single quotes (') to double quotes (")
    • remove leading and trailing spaces (i.e. remove spaces at the beginning and at the end)

For example, this line from the script:

mongo --host M312/m1 --eval '
rs.isMaster().primary
'

Should be run like this in the Windows terminal:

mongo --host M312/m1 --eval "rs.isMaster().primary"

I forgot to mention one other crucial point, the mongod.conf file was not binding to the 192 IP, so restart the nodes with bind_ip before initiating the replica set, like this:

# Shutdown
vagrant ssh m1 -- -t 'mongod -f /shared/mongod.cnf --shutdown'
vagrant ssh m2 -- -t 'mongod -f /shared/mongod.cnf --shutdown'
vagrant ssh m3 -- -t 'mongod -f /shared/mongod.cnf --shutdown'

# launch mongod on different nodes
vagrant ssh m1 -- -t 'mongod -f /shared/mongod.cnf --bind_ip localhost,192.168.15.101'
vagrant ssh m2 -- -t 'mongod -f /shared/mongod.cnf --bind_ip localhost,192.168.15.102'
vagrant ssh m3 -- -t 'mongod -f /shared/mongod.cnf --bind_ip localhost,192.168.15.103'

@Sonali_Mamgain, please see bind_ip feedback for your colleagues

1 Like

Hi @007_jb,

Thanks for looking into the issue and sharing the feedback!! I will check this and make the updates.

Kind Regards,
Sonali

Thank you so much buddy! I try it accordingly, but it did not work. I appreciate it though.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>vagrant ssh m1 -- -t 'mongod -f /shared/mongod.cnf --shutdown'

killing process with pid: 13204
Connection to 127.0.0.1 closed.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>vagrant ssh m1 -- -t 'mongod -f /shared/mongod.cnf --bind_ip localhost,192.168.15.101'
about to fork child process, waiting until server is ready for connections.
forked process: 3175
child process started successfully, parent exiting
Connection to 127.0.0.1 closed.

C:\Users\Cal Qiu\university\m312\nodes-vagrant-env>mongo --host 192.168.15.101 --eval '  rs.initiate({    "_id": "M312",    "members": [      {"_id": 0, "host": "192.168.15.101"},      {"_id": 1, "host": "m2.university.mongodb"},      {"_id": 2, "host": "m3"},    ]  })'
MongoDB shell version v4.2.2
2020-05-04T08:08:00.267-0700 F  -        [main] exception: Database name cannot have reserved characters for mongodb:// URL: mongodb://192.168.15.101:27017/rs.initiate%28%7B
2020-05-04T08:08:00.269-0700 E  -        [main] exiting with code 1

I gave you the exact line of code. All you had to do was copy, paste and run.

Gotcha Man! Great appreciated! :hugs:

Fyi re your code, you didn’t follow the guidelines that I mentioned that’s why it didn’t work:

Yes. It’s kind of you! :grinning:

1 Like