I am a newbie to MongoDB and having an issue connecting to MongoDB from the terminal.
MongoDB Tutorial on YouTube
When I tried to connect to MongoDB from the terminal in VS Code, I've got an error saying; "MongoServerSelectionError: read ECONNRESET".
What I did is that I googled and unchecked the Proxy Strict SSL in settings, then reloaded the window and ran the command below.
mongosh "mongodb+srv://cluster0.8tjjn.mongodb.net/myFirstDatabase" --apiVersion 1 --username mongo
The username is correct as shown, mongo. I was asked for my password and typed it correctly. It's just 5 letters password, so it's hard to imagine I mistyped it a few times in a row.
I double-checked if I installed mongo and mongosh by running:
mongo --version
↓output
mongo --version
MongoDB shell version v5.0.6
Build Info: {
"version": "5.0.6",
"gitVersion": "212a8dbb47f07427dae194a9c75baec1d81d9259",
"modules": [],
"allocator": "system",
"environment": {
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
Also
mongosh --version
↓output
1.2.2
After the two commands, I ran below and typed the password.
mongosh "mongodb+srv://cluster0.8tjjn.mongodb.net/myFirstDatabase" --apiVersion 1 --username mongo
The YouTuber explained how to connect it in a straightforward way, so I am guessing if my mac air has a problem in it such as the too old version. I still use macOS Mojave 10.14.6 causing some installation problems so far. I can't install a newer OS due to the lack of storage. It has 128GB and most of it is accounted for systems. I sometimes need to restart it when it's slow and have been thinking to buy a new one.
Thanks a lot in advance:)
Related
My objective is to run a MongoDB Atlas cloud backup locally on my mac.
For the longest time, the procedure was simply:
Download backup
Extract tar -xvzf restore-<name>.tar.gz
mongod --dbpath restore-/ --port 58109
Connect with Atlas and debug.
But this does not work anymore, because MongoDB Atlas is running 6.1 --> and I'm running community local (6.0). When I try, I get this error:
Wrong mongod version
...
admin.system.version: { _id: \"featureCompatibilityVersion\", version: \"6.1\" }
...
Invalid feature compatibility version value, expected '5.0' or '5.3' or '6.0. See https://docs.mongodb.com/master/release-notes/5.0-compatibility/#feature-compatibility.
...
To review full details, see the community post https://www.mongodb.com/community/forums/t/problems-running-a-downloaded-backup-from-atlas-possible-version-mismatch/209094.
I'm having trouble getting started with MongoDB via SSH on a VPS. Note that MongoDB was installed by admins with the VPS service, not me. I have to presume they installed it correctly. Unfortunately, they provide zero support documentation and I can't figure it out after reading countless official MongoDB docs and even more found elsewhere.
I am able to SSH into the remote server just fine. I can check the MongoDB version, and mongosh is there, too. But I cannot figure out how to get to the point where I can create a new collection, or even start MongoDB, if that's what I need to do.
Here are some of the things I've tried in the shell for the VPS. The closest I've gotten is by running mongosh -nodb which seems to get me inside of MongoDB, but I know that option means "no database," so it's not what I need to do.
$ ssh customusername#207.196.153.34
Last login: Thu Dec 29 11:56:53 2022 from 82.204.238.49
customusername#customdomain.com [~]# mongod -version
db version v6.0.3
Build Info: {
"version": "6.0.3",
"gitVersion": "f803681c3ae19817d31958965850193de067c516",
"openSSLVersion": "OpenSSL 1.0.1e-fips 11 Feb 2013",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "rhel70",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
customusername#customdomain.com [~]# mongosh --version
1.6.1
customusername#customdomain.com [~]# mongosh -nodb
Current Mongosh Log ID: 63abf66ca872ab436a8040c8
Using Mongosh: 1.6.1
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
> use test-db
MongoshInvalidInputError: [SHAPI-10004] No connected database
> exit
customusername#customdomain.com [~]# mongosh --username customusername
Enter password: ********************************
Current Mongosh Log ID: 63abf8c15a47f0e078be3d76
Connecting to: mongodb://<credentials>#127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.1
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
customusername#customdomain.com [~]#
I am able to pull up "help" files. And I've tried multiple variations of # mongod mongodb://customusername#127.0.0.1:27017/ which fail.
customusername#customdomain.com [~]# mongod help
customusername#customdomain.com [~]# mongosh -h
customusername#customdomain.com [~]# mongod mongodb://customusername#127.0.0.1:27017/
That last command returns a few lines which indicate it might be working, then it fails with message: "Invalid command: mongodb://customusername#127.0.0.1:27017/" And then it displays a number of "General options" such as "-h [ --help ]". I can't make sense of most of them.
Note that I cannot install MongoDB/mongosh locally because my machine is too old, so I have to be able to log in through SSH and handle it that way. If I can figure it out via SSH, maybe I'll try something like MongoDB Compass next, which I am able to install locally.
Thank you for your time and assistance.
UPDATE: I think I've made progress, but am still not there yet.
I think I got MongoDB running with this, after creating a directory called "mongodb" to hold data files:
# mongod --port 28015 --dbpath ./mongodb/
A string of messages come up in my terminal, with the last being related to listening ("ctx":"listener","msg":"Waiting for connections"), and the process appears to continue running.
I then open a new terminal window, SSH in, and run this:
# mongosh --port 28015
Which appears to land me in a mongo shell in which I'm able to create a new collection:
test> use test-db
switched to db test-db
test-db>
Also, I notice that the original terminal window with the open process outputs connection-related messages as I interact with the second window (e.g. "ctx":"listener","msg":"Connection accepted").
I looked inside of the /mongodb/ directory and there are a number of mongo-related files in there now, "collection-0-5001736531146682033.wt", "index-1-5001736531146682033.wt", "storage.bson", and so forth. So, I think the db creation is working.
UPDATE TWO
Was struggling with why the show command was throwing an error, since use was already working, then figured out I needed to insert a document first:
test> db.tours.insertOne({name: "Some Name", price: 19, rating: 3.5})
The full command is show dbs and then the "test" database appears.
So, you can check out my two updates above. I was able to access and do very basic operations with MongoDB on a VPS with SSH.
Also, here are some helpful links, if you struggle with similar issues.
Mongo Shell basics:
https://www.mongodb.com/basics/get-started#get-started-with-mongodb
(skip down to the "Get Started with MongoDB" subsection, since the top of the page is about the Atlas interface)
Setting up admin and user accounts via command line:
https://medium.com/#haxzie/getting-started-with-mongodb-setting-up-admin-and-user-accounts-4fdd33687741
Good luck!
I am new to MongoDB. I already read the docs and MongoDB Community Edition.
It is working
but, I tried to run the "mongo" command: It is not working!!
...So i did:
sudo apt install mongodb-clients
(I saw after that this command uninstalled the mongodb server, which i had to install again)
When it finished, i tried again the "mongo" command. It is not working !!
How do I solve this?
You may want to try "mongosh" command.
As specified on documentation you provided.
Start a mongosh session on the same host machine as the mongod. You
can run mongosh without any command-line options to connect to a
mongod that is running on your localhost with default port 27017.
You need a client in order to interact with mongoDB deployment such as mongosh or Compass.
The MongoDB Shell, mongosh, is a fully functional JavaScript and
Node.js 16.x REPL environment for interacting with MongoDB
deployments. You can use the MongoDB Shell to test queries and
operations directly with your database.
Hope It helps.
The mongodb-server and the mongodb-clients debian packages were for MongoDB 3.x, maintained by Ubuntu.
Since MongoDB 4.x, MongoDB provide their own debian packages, but they named them mongodb-org-server, mongodb-mongosh and mongodb-cli. The client command mongo is split into two different commands mongocli and mongosh.
I need help to solve an error that happened while installing MongoDB into Macbook.
I run this command to kick off installing.
brew install mongosh
ALthough I got a warning msg, it seemed like fine.
I waited so long, and the installation got finally done.
Here is the screenshot of the end.
As you can see, I typed below to check if it was successfully installed.
mongosh --version
1.2.2
Finally I tried to run MongoDB, so typed "mongosh". And I got an error to run it and connect to db called cluster0.
mongosh
Current Mongosh Log ID: 621d2adedeee61396fddb367
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.2
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
takeichimasahironoMacBook-Air:~ masa$ mongosh "mongodb+srv://cluster0.8tjjn.mongodb.net/myFirstDatabase" --apiVersion 1 --username mongo
Enter password: *****
Current Mongosh Log ID: 621d2b0f5a5370a82628edcc
Connecting to: mongodb+srv://cluster0.8tjjn.mongodb.net/myFirstDatabase?appName=mongosh+1.2.2
MongoServerSelectionError: read ECONNRESET
Any idea to solve this issue?? Thanks for your effort in advance.
In addition to the good answer above -- On newer versions mac os x the root directory is read only so you will need place your mongo data directory somewhere else, see this thread:
Read-only file system when attempting mkdir /data/db on Mac
I also needed to separately install the mongo command line tool from the cask:
$ brew install mongodb-community-shell
I recommend Homebrew for installing and managing applications on macOS. It is installed using the following command in the macOS terminal. Open up the terminal and paste the command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The terminal runs through a series of installation operations, and will probably create folders in your local machine to accommodate Homebrews storage requirements. You can find more detailed instructions here. After it's installed, update the Homebrew dependencies and install MongoDB on the command line:
brew update
brew tap mongodb/brew
brew install mongodb-community
It will take a few seconds. Once it's done, create a directory so MongoDB can store its data.
sudo mkdir -p /data/db
Now to make sure this data directory have the right permissions, you'll run this command:
sudo chown -R `id -un` /data/db
Now our data directory is ready with the right permissions. Next run mongo daemon. Which is a service which runs in the background and listens for connections on a given port. Run this command:
mongod
Now mongo daemon will be running in the background and can be used by your applications. Next, check your MongoDB version:
mongo --version
MongoDB shell version v4.2.6
The command-line results will show the version you have installed on your local machine. I recommend using the latest version of libraries and software whenever possible to avoid compatibility issues with client-side applications.
I have been trying to access my mongo instance from another machine, but I get this error. I could not find many references to this whatsmyuri error. This is what I get from the external machine:
$ mongo <IP_ADDRESS>:27017/youtube_advertising -u user -p password
MongoDB shell version: 3.2.0
connecting to: <IP_ADDRESS>:27017/youtube_advertising
2016-02-19T17:10:02.923+0100 E QUERY [thread1] Error: network error while attempting to run command 'whatsmyuri' on host '<IP_ADDRESS>:27017' :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
I have already changed the /etc/mongod.conf file, opened connections through port 27017 (with iptables) and restarted mongo. I am able to connect via ssh to that machine.
Searching about this whatsmyuri, I ran this command on mongo:
> db.runCommand( { whatsmyuri: 1 } )
{ "you" : "127.0.0.1:36990", "ok" : 1 }
I do not know if that 36990 port is right or wrong. Just in case I opened connections from there too, but still nothing.
Any ideas?
UPDATE
Checking the /var/log/mongodb/mongod.log, this is what I get when I try to connect from remote:
2016-02-19T10:41:07.292-0600 I NETWORK [initandlisten] connection accepted from <EXT_IP_ADDRESS>:51800 #2 (1 connection now open)
2016-02-19T10:41:07.310-0600 I QUERY [conn2] operation isn't supported: 2010
2016-02-19T10:41:07.310-0600 I - [conn2] Assertion: 16141:cannot translate opcode 2010
Check your versions. That may help.
I was having the same problem. In my case, the server was version 3.2.0-rc2, while mongo shell version was 3.2.1.
Upgrading the server to 3.2.1 fixed the problem.
This issue bit me when I was running two versions (3.4 and 4.2) of MongoDB on the same Windows 10 machine. I ran v3.4 mongod with no problems mentioned in the console output, but then running the v3.4 mongo shell produced the above error. Checking the Task Manager, it turned out there was a MongoDB process (I'm not sure, but I think it was for v4.2) running. After ending that process through the Task Manager, the v3.4 mongo shell ran fine with no error.
Using mongodb-community-shell
In MacOs brew install mongodb/brew/mongodb-community-shell
It will ask you to overwrite link with mongo command.
brew link --overwrite mongodb-community-shell
The issue arises when the mongo client's and server's version mismatch.
Uninstall MongoDB from the client and for installation follow the detailed instruction provided over here.
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
The key step which needs to be done with the attention is
sudo apt-get install -y mongodb-org=4.2.7 mongodb-org-server=4.2.7 mongodb-org-shell=4.2.7 mongodb-org-mongos=4.2.7
mongodb-org-tools=4.2.7
Note: In my case, the mongo version of server was 4.2.7
Another thing that one can do is uninstall MongoDB from both the systems taking necessary backups and install it again.