Launching MongoD first lab

Tried to launch mongod with the following

mongod --port 27000 --dbpath data/db --logpath data/db/momgod.log --fork

execute and came back error.
then tried in one shell
mongod --port 27000
and in another
mongo --port 27000
this seemed to work when I ran the admin script.
Below is a screen shot of this. Then went to validate as suggested and got the result as shown.

error message

Instruction on how to do things are poor and not updated. I await your response.

That’s a matter of opinion. The requirements are
data files are stored in /data/db/ and yet you write

Just to be clear you are missing a slash. From your screen shot you enter the command mongo admin --host … while you are already in the mongo shell. I was not able to find where it was written to type this command while already in the shell. Mistakes happen but please do not blame the instructions when you do not follow them.

… plus
image

Once again, I’m stuck. Please clarify a few points.
p.s. I am using tis post because I have the same missunderstandig and I stuck on the same point.

  • When I am running cmd. I understand it is a command prompt. What the different when I am running it as Admin, when I am running Node.js or other?

  • When I printing cd c:\m103\m103-vagrant-env I am actually inside the folder m103-vagrant-env
    From that folder, I am running vagrant up.

What command I can use to check where I am now?

  • If I got an massage after vagrant up:
    ==> mongod-m103: Machine already provisioned. Run vagrant provision or use the --provision
    ==> mongod-m103: flag to force provisioning. Provisioners marked to run always will still run.

Does it mean that the server wasn`t shutdown? Ii yes, do I need to run vagrant provision each time? Or I need provision every new connection or only when I have some problem?

  • In that point I understand that I am still in my local machine. To connect to VM, I need to run vagrant ssh?

  • When I see: vagrant@m103:~$ Dose it mean that I am in VM now?

  • Now, to connect to mongod I am running: mongod

Now – Where am I?

  • I am running second cmd (If the first window is cmd, the second window have to be cmd also from the question above or it doesn`t matter?

  • In new cmd window, Do I have also to run here first vagrant shh?

I am not sure how to:
• run on port 27000
• data files are stored in /data/db/
• listens to connections from the IP address 192.168.103.100 and localhost
• authentication is enabled

So, Now I am running: mongo (in my second cmd window)
mongo admin --host localhost:27000 --eval ’
db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

I got: '2020-02-22T02:39:31.448+0000 E QUERY [thread1] Error: couldn’t add user: User “m103-admin@test” already exists :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1
I understand that I did it successfully some how previous time and it is already exist.


I don`t understand now:

  1. Chapter 1: The mongod/Lab-Launching Mongod . Where exactly I need to run: validate_lab_launch_mongod???
  2. How to quit from here? I am totally confused where exactly and when I need to use A. db.shutdownserver() B. exit C: quit()

Exit- is to exit from here: MongoDB Enterprise > to here: vagrant@m103:~ Does it mean that in that moment I have 2 cmd windows are in same position? ![Screenshot (127)|690x388](upload://9dCiaBCNDj1AQYean7wj4f1iwH2.png) When I am using exit command here: vagrant@m103:~ exit
logout
Connection to 127.0.0.1 closed.
Connection was closed – dose it mean I am 1 step back from vagrant shh?
What happen with the second cmd windows – I am still connected there by shh? (If I am on line:

Where I need to use quit()?

Your comment
“When I see: vagrant@m103:~$ Dose it mean that I am in VM now?”
Yes you are on Vagrant unix box
You have run validate_lab_launch_mongod correctly on vagrant@m103
It gave error because setup was not correct or mongod not running or running on wrong port or user not created
So please check how you started your mongod
You can check by ps -ef|grep mongod

Please don’t get confused by Windows cmd and Unix command
You have to run all your commands on vagrant box only
You can open multiple sessions of your vagrant unix box by vagrant ssh

1 Like

Please show the command you used to start mongod
Your outputs show bit jumbled and has syntax errors

Please don’t run ps -ef commands at mongo prompt.It will fail
You have to run at os prompt
MongoDB Enterprise>–>this is mongodb prompt which indicates you are connected to mongo DB

vagrant@m103:---->This is Unix prompt

Please go thru your lectures again.I agree it is bit confusing if you don’t have Unix experience but you can overcome it

Hi I found it also confusing. I finally got it to work by starting mongod like

mongod –port 27000 –bind_ip localhost,192.168.103.100 –dbpath /data/db --logpath /data/log –fork

if I did not have the bind then mongo –port 2700 etc would give a bind error .

also had to do mkdir data/db and mkdir data/log.

Checked notes and bind_ip not given had to figure that out myself.

2 Likes

Good job you figured it out
I think bindip part is covered in the next chapter
Please avoid posting the commands,potential solutions to labs
It is against forum guidelines
Try to mask or remove the commands

@007_jb







I have tried also that:

And when I am shutig down my computer I have a message


What I am missing???

Hi Semion_79117

There is nothing wrong with your vagrant or Virtual box
You are running commands at wrong prompts or wrong windows
Please read your lab requirements and go step by step
You will be able to complete with ease
Don’t run mongo,mongod at mongo prompt
Need to run from os prompt
Without starting your mongod with appropriate parameters no use in running in validate
It is bound to fail
If just run mongo it will connect to default mongo instance which is not needed
1.bring up mongod on required port with proper dbpath and logpaths-make sure dirs exist
2connect by mongo --port specifying your port number
3.create user
check logs make sure everything as per lab requirements and then run validate script
Also you are not using – with fork option

1 Like

I did it.
I think my problem that i can`t create a user.
Without starting your mongod, right after vagrant up, I am runnig the following validation script (I am in my vagrant (after vagrant up) and outside the mongo shell (before some steps and after vagrant is up) I entering the validation key
mongo admin --host localhost:27000 --eval ’
db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

This is what I get

Then I have tried to go by yours recomendtion

Bringing up mongod on required port with proper dbpath and logpaths

Make sure dirs exist - at the very top on the right window
2connect by mongo --port specifying your port number - on the left window
3.create user - I Think I did it but somting wrong :frowning:

I am cheking the user exist



Again I am shutdown the server, exit from shell and trying to run my script there

I have gone thru all your snapshots
I repeat you are making mistakes in running the commands
If mongod is already up and you connected to mongo prompt why you are running mongod again?
Those syntax errors you see are all because of this
mongo,mongod commands& validation scripts should be run at os prompt

You are completely exiting vagrant box and trying to run commands at Windows C: prompt.It is not correct
From Windows you login to Vagrant by vagrant ssh.Once you are on vagrant Unix box complete all your steps on this box only
You tried to start mongod with insufficient parameters and later you are trying to run mongod again with more parameters
Please kill the existing mongod
Prepare your commands in a notepad with all requirements then run step by step
It will work
As i mentioned previously even if you miss one parameter your validation will fail

1 Like

out of despair

What is os promot it was my question, I think I understanding it now.

What you mean by

Like @Ramachandra_37567 surmised, there seems to be a lot of confusion over when to run what and where. So here’s a summary:

  1. C:\m103\m103-vagrant-env>
    If your machine is up and running, the only thing you need to run here is vagrant ssh
    vagrant ssh will log you into the Linux VM
    Don’t run any other commands.

  2. vagrant@m103:~$
    This is the Linux environment (VM) where you will do all the work throughout this course.
    It’s here that you run Linux commands, mongod and mongo
    You will typically run commands to create directories, list files, initiate a mongod server or connect via mongo

  3. MongoDB Enterprise >
    You are now inside the MongoDB database. You cannot run mongod or mongo commands here.

  4. Make sure you switch to the admin db before you run db.createUser() or use the script provided in the lab (below) which does all that for you.
    You have one chance (and one chance only) to create the first user, so if you make a mistake (such as creating the user on the wrong database, spelling mistake etc), you need to kill/shutdown the db, delete all the data files and start again.
    image

  5. To switch to the admin database:
    use admin

  6. To check which database that’s currently in use:
    db

1 Like

Thanks for the detailed answer

How exactly I need to do it?

You specified the data files in the dbPath. Delete the files like so:
rm -r /path/to/directory/*

PS: Make sure that it ends with “/*” as above

Sorry for the question again. Where I should to run that command?

After reading post #15 again, where do you think it should be run? Bearing in mind that it is a Linux command.

Ok. I will start again step by step. Thank you @Ramachandra_37567 and @007_jb