~$ mongo
MongoDB shell version: 2.2.3
connecting to: test
>
why is my server name test? and where can I change it?
'test' is the default database.
You can change current db with the help of use command.
use NewDatabaseName
If "NewDatabaseName" is not exist it will be created in Mongo.
Related
I switched my db properly and also confirmed that there is a document in my collection but I cannot find any collection by 'show collection' command.
Can I know the reason?
Please check your Mongo shell version and MongoDB version are compatible.
Refer to this JIRA ticket which has the similar issue reported. The root cause of the problem was the Mongo shell version and MongoDB version were not compatible.
To get Mongo Shell version:-
Go to the bin folder and execute mongo command which will print the Mongo shell version in the first line.
To get MongoDB version:-
db.version()
According to this documentation using use mays should create a db if it isn't already created:
MongoDB use DATABASE_NAME is used to create database. The command will
create a new database, if it doesn't exist otherwise it will return
the existing database.
So why doesn't mongo use mays work?
root#server88-208-249-95:~# mongo use mays
MongoDB shell version: 2.6.11
connecting to: use
2015-09-16T22:17:20.316+0100 file [mays] doesn't exist
failed to load: mays
The 'use' command doesn't work with mongo command.
You have to open mongo shell and then use the 'use' command.
Open terminal -> enter 'mongo' to get mongo shell ->
use db_name
This will create a DB if it doesn't exists already.
A DB doesn't show up when using 'show dbs' until you create a collection in it.
Use db.createCollection("collection_name") and then use 'show dbs' and you will see your newly created DB.
You need to create at least one collection before it saves the database. Issuing a use will create it, but will not automatically save it. You can create an empty collection with db.createCollection("test"). To verify try the following commands from the mongo shell:
use mays
show dbs (mays will not show up)
db.createCollection("test")
show dbs (mays will show up)
I am using Docker to add mongodb 2.6.5 to a host that already had 2.4.9 installed and I am sharing the data directory.
When I run the 2.6.5 (in container) I get permission issues apparently due to changes in 2.6:
http://docs.mongodb.org/manual/tutorial/add-user-to-database/
But when I try to add a user with role roleAdminAnyDatabase I get "No role named roleAdminAnyDatabase#admin"
Do I need to migrate the data? What is the best way to do that?
I assume I could start up 2.6.5 with no data files and mongorestore the data from 2.4.9. But, does that mean I cannot run 2.4.9 using that directory anymore?
I am using PhpStorm editor with mongoDB plugin, I was wondering what should be the mongodb server url,so I could monitor my mongoDB's activities directly from PhpStorm
It depends if you set MONGO_URL. If you run meteor locally with out setting MONGO_URL try
mongo localhost:3001/meteor
If you have deployed your app to meteor.com try
meteor mongo yourapp.meteor.com --url
This will return the MONGO_URLso that you can monitor/backup/restore your DB. Eg
mongodb://client-lots-of-numers#production-db-a1.meteor.io:27017/yourapp_meteor_com
When running MongoDB using the meteor command line you can access the database at localhost:3001. The database name is meteor and there is no need for credentials.
I have my MONGO_URL set to mongodb://localhost:27017/meteor and have the MongoDB run as a service.
When running my project it seems OK to store data to the separate MongoDB until I tried to run meteor reset.
My assumption is it tried to remove its default database. The error complained that myproject.meteor\local is not empty and pointed to fs.js:456 which goes to files.js:256 (rm_recursive) and so on.
any idea what and how I can fix this?
$ meteor reset only resets the bundled MongoDB. It won't reset an external Mongo database.
(That's something we should explain better in the documentation.)
In your case, try connecting to the Mongo database directly (with the mongo command line shell) and running > db.dropDatabase()