Trying to get started with mongodb and linux at all, so got a preety stupid question, but anyways. How can i get into the mongodb(cmd) to send some of my queries.
Used
sudo mongodb serive start
already and cheked it's status, how can I access that space where i can type my queries?
The command is just mongo.
$ mongo
MongoDB shell version: 3.2.1
connecting to: test
Server has startup warnings:
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten]
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten]
> exit
bye
Related
At first I had a problem where the mongod service stopped working altogether. Thereupon I completely uninstalled mongodb and reinstalled it and followed instructions per this thread: https://askubuntu.com/questions/921753/failed-to-start-mongod-service-unit-mongod-service-not-found
This caused the mongod service to finally start.
In order for it to work, I also had to follow instructions from this thread:
mongo - couldn't connect to server 127.0.0.1:27017
So far this configuration has worked only 1 time and that was after I followed the instructions to remove the .lock file in the mongod directory and then repair mongod.
I also tried to remove the sock file like stated here: MongoDB Failing to Start - ***aborting after fassert() failure
Full project reset
Then I tried just disconnecting the project entirely; close nodemon for backend, exit ng serve on frontend, stop and remove mongo docker container... And tried again. Here is my step-by-step process after everything should have been fixed:
Restart mongod service
sudo service mongod restart
Restart frontend (executed from frontend directory)
ng serve frontend
Restart backend (executed from backend directory)
npx nodemon backend
Restart mongo container (executed from deploy directory, mongo is the docker container name, I'm building it from existing provided deploy script)
sudo docker-compose up -d mongo
sudo docker ps -a # check container was created and is running
Debugging information:
sudo service mongod status
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset:
Active: active (running) since Thu 2020-01-09 11:21:43 CET; 3min 40s ago
Docs: https://docs.mongodb.org/manual
Main PID: 17242 (mongod)
CGroup: /system.slice/mongod.service
└─17242 /usr/bin/mongod --config /etc/mongod.conf
janv. 09 11:21:43 junior-LIFEBOOK-E752 systemd[1]: Started MongoDB Database Server
sudo mongod2020-01-09T11:25:45.983+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] MongoDB starting : pid=17727 port=27017 dbpath=/data/db 64-bit host=junior-LIFEBOOK-E752
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] db version v4.2.2
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] allocator: tcmalloc
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] modules: none
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] build environment:
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distmod: ubuntu1804
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distarch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] target_arch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] options: {}
2020-01-09T11:25:45.987+0100 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] now exiting
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] shutting down with code:48
sudo mongo
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8e813fc2-049c-440d-83ce-0b1d8516c4d0") }
MongoDB server version: 4.2.2
Server has startup warnings:
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten]
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten]
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-01-09T11:21:44.848+0100 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()
So something weird is happening here, it doesn't find the database from the project and I have no clue why. As far as I can see, it creates a new database including my system details.
How can I fix this please and connect to the project database? I can't move further until I do.
it's been resolved. First I found out I didn't need to have the mongod service running locally because mongo was already included in the docker container. But actually this wasn't a database issue at all. There were a few things going wrong like there was a proxy but the command had been changed to execute the connection, endpoints were on localhost but weren't supposed to be, and the content I was expecting to see had been hidden by a careless push from another developer. Fun times! But we can move on now. Thanks to the people who tried to help!
Unable to connect my local MongoDB server from AWS EC2 instance, whereas I am able to connect vice versa.
From EC2 to Local Mongod server:
root#ip-172-31-31-13:~# mongo -u krishna -p Kmk123## 192.168.0.104/admin
MongoDB shell version v4.0.12
connecting to: mongodb://192.168.0.104:27017/admin?gssapiServiceName=mongodb
2019-08-26T16:48:14.271+0000 E QUERY [js] Error: couldn't connect to server 192.168.0.104:27017, connection attempt failed: SocketException: Error connecting to 192.168.0.104:27017 :: caused by :: Connection timed out :
connect#src/mongo/shell/mongo.js:344:17
#(connect):2:6
exception: connect failed
root#ip-172-31-31-13:~#
From Local to AWS EC2 :
[root#krishna ~]# mongo -u root -p root123 ec2-18-206-199-178.compute-1.amazonaws.com/admin
MongoDB shell version v4.0.12
connecting to: mongodb://ec2-18-206-199-178.compute-1.amazonaws.com:27017/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a6b35f6a-3e71-4ada-b10a-c0783743837b") }
MongoDB server version: 4.0.12
Server has startup warnings:
2019-08-26T16:36:21.897+0000 I STORAGE [initandlisten]
2019-08-26T16:36:21.897+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-08-26T16:36:21.897+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-08-26T16:36:22.912+0000 I CONTROL [initandlisten]
2019-08-26T16:36:22.912+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten]
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten]
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten]
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-08-26T16:36:22.913+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-08-26T16:36:22.913+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()
>
>
I have edited SG of EC2 instace as below:
SSH TCP 22 0.0.0.0/0 Custom TCP Rule TCP 27017 0.0.0.0/0 Custom TCP
Rule TCP 27017::/0
You need to update mongod.conf file to allow your mongodb accessed from remote. It works for me when I do all the things mentioned in following page.
Ref: https://ianlondon.github.io/blog/mongodb-auth/
I want to use MongoDB with my Rails app.
The error is not uncommon but none of the suggestions has worked for me.
I've installed mongodb using homebrew and followed the folowing the steps for same
brew update
brew install mongodb
sudo mkdir -p /data/db
sudo chmod 777 /data/db
brew tap homebrew/services
I use brew services start mongodb to start my mongodb server and get the following response
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] MongoDB starting : pid=39164 port=27017 dbpath=/data/db 64-bit host=C168s-iMac.local
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] db version v3.6.2
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] allocator: system
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] modules: none
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] build environment:
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] distarch: x86_64
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] target_arch: x86_64
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] options: {}
2018-02-08T12:27:59.089+0530 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-02-08T12:27:59.089+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-02-08T12:28:01.222+0530 I STORAGE [initandlisten] WiredTiger message [1518073081:222686][39164:0x7fffa9db0340], txn-recover: Main recovery loop: starting at 2/18944
2018-02-08T12:28:01.330+0530 I STORAGE [initandlisten] WiredTiger message [1518073081:330012][39164:0x7fffa9db0340], txn-recover: Recovering log 2 through 3
2018-02-08T12:28:01.442+0530 I STORAGE [initandlisten] WiredTiger message [1518073081:442109][39164:0x7fffa9db0340], txn-recover: Recovering log 3 through 3
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2018-02-08T12:28:02.572+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-02-08T12:28:02.572+0530 I NETWORK [initandlisten] waiting for connections on port 27017
2018-02-08T12:28:09.302+0530 I NETWORK [listener] connection accepted from 127.0.0.1:51073 #1 (1 connection now open)
2018-02-08T12:28:09.302+0530 I NETWORK [conn1] received client metadata from 127.0.0.1:51073 conn: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.6.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "17.2.0" } }
Along with this I also start mongo
cd /usr/local/bin
mongod
which starts as expected.
I created my rails app without the ActiveRecord and used mongiod gem. Next i created the config file using rails g mongoid:config and added Mongoid.load! './config/mongoid.yml' in application.rb file so the config file is loaded.
The content for mongoid.yml is
development:
clients:
default:
database: mongo_db_demo_development
hosts:
- localhost:27017
test:
clients:
default:
database: mongo_db_demo_test
hosts:
- localhost:27017
options:
read:
mode: :primary
max_pool_size: 1
I created my scaffold for Person and the model was created as expected using include Mongoid::Document. I went ahead and used the index of person as my root_path.
When i run the rails server, I get the following error
ActionView::Template::Error (No server is available matching preference: # using server_selection_timeout=30 and local_threshold=0.015):
I know its an exception by rails but cant seem to resolve it for hours now.
I referred this tutorial to get started. The weird thing is that I was successful to set up the app in accessing it and the next day it crashed with this error without any changes. I'm able to access the books's new page /books/new but cant seem to save it, hence making it clear that the app is unable to access the database.
I've since uninstalled mongodb twice wondering if the installation has some problem but cant seem to figure out whats wrong.
I understand there are many similar questions but none to resolve my issue. I don't understand what I'm missing and going wrong. Any help is appreciated.
Thanks
Update
I was somehow able to run another project that had active record and mongodb in it. Here is the same. I was successful in saving the data to the post model proving that the mongod and mongo are running and the setup is done correctly. Which means that I'm missing something in my app configuration but yet, I've no clue.
How to specify in MongoDB 3.2.8 an absolute path?
I do this
use mydb
db.mycollection.findOne()
Howto write that without use mydb? The absolute path to db and collection. I use mongo shell.
Edit after first answer:
I have many databases and when specify a database a login time, to switch database I would again have to use use otherdb. I really wish some kind of absolute path, this is also possible in MariaDB/MySQL (select * from mydb.mytable).
when you connect to mongod when open console, you can specify db to conncet to:
$ mongo mydb
MongoDB shell version: 3.2.7
connecting to: mydb
Server has startup warnings:
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten]
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten]
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten]
> db
mydb
I am trying to setup the authentication on MongoDB. I've uncommented auth=true in configuration file and restarted the server. The first connection via mongo was rejected. The second one (immediately after the first one) went through and I got this in the logs:
Sat Apr 12 14:56:46 [initandlisten] connection accepted from 127.0.0.1:44001 #1
Sat Apr 12 14:56:46 [conn1] note: no users configured in admin.system.users, allowing localhost access
While in console, I am able to execute commands, however if I try to follow any of the numberous tutorials (including the official ones), I get either db.createUser is not a function when executing db.createUser() or password can't be empty when executing db.addUser():
The object which I am passing is:
{
user: "username",
pwd: "passphrase",
roles: [
{
role: "userAdminAnyDatabase",
db: "admin"
}
]
}
What version of mongodb are you running? db.createUser was introduced in version 2.6
Deprecated since version 2.6: Use db.createUser() and db.updateUser() instead of db.addUser() to add users
to MongoDB.
In 2.6, MongoDB introduced a new model for user credentials and privileges, as described in Security Introduction. To use db.addUser() on MongoDB 2.4, see db.addUser() in the version 2.4 of the MongoDB Manual.
http://docs.mongodb.org/manual/reference/method/db.addUser/
Regarding my experience, this issue also happens when you have an old version of Mongo Shell.
So, be sure to have the Mongo Shell according to the version of your MongoDB Server.
$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Below:
$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Server has startup warnings:
2018-01-16T11:43:00.195-0600 I STORAGE [initandlisten]
2018-01-16T11:43:00.195-0600 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-01-16T11:43:00.195-0600 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
>
> use admin
switched to db admin
>
> db.createUser( {user:"mongoloide", pwd:"mongoloide*2017", roles:["root"]} )
Successfully added user: { "user" : "mongoloide", "roles" : [ "root" ] }