Mongo shell keep passing document into default database "test". Eventhough I've already set to another database - mongodb

I've set mongo database to current database using use currentdb.
When inserting data from local host. The data keeps entering into default database "test".

Running use <databasename> in the shell affects only the current session.
If you then connect with node.js/mongoose and use .save(), that will be a separate session.
To find out the database being used by a mongoose connection, check the name property.
To set the database name when connecting, specify the name in the URL like:
mongoose.connect('mongodb://user:pass#localhost:port/database');

Related

How to set default database in Postgresql database dump script?

I'd need to initialize postgres instance to Docker container from dump SQL-file. Otherwise it works fine but the problem is I cannot set database to be something else than "postgres". Creating new database works fine but schema clauses eg. CREATE TABLE end up going nowhere.
I tried to set default database with --env option in docker run command but it returns error --env requires a value.
Is there any way to set default database? Hopefully in SQL-clause.
Apparently you need to use /connect "dbname=[database name]" before schema clauses in order to point script towards correct dabase.
This wasn't (quite understandbly) included into the script when dump was generated only for a single database instead of the whole cluster.

MongoDB database creation issue

I am using MongoDB. All I want to do is add a collection to a database I have created. I verified before I even started that the database existed by running the command "show dbs". However, when I try to add the collection to that database, it says that this database is undefined. Any thoughts or suggestions? Here were the commands I typed in terminal
use myDB
myDB.myCol.insert({"id":"1"})
the response I got from this command is "myDB is not defined" even
though I verified that it exists with the command "show dbs".
Use db instead of the name of the database in your insert command:
db.myCol.insert({"id":"1"})
use MyDB sets which database db refers to.

How to access the database imported through datapump

I just imported data dump through below command:
IMPDP user/pass FULL=Y DUMPFILE=BIRDV24012014.DMP LOGFILE=BIRDV24012014.log;
The dump has been restored the issue is i dont know how to connect to this database that i just imported, what service or TNS does it resides and how can i query it?
You didn't import a database, you imported the contents of your file into your existing database. If you could successfully run impdp user/pass then your ORACLE_SID etc. is already set and you should be able to log in and query with sqlplus user/pass.
If you've come from another RDBMS background you may be confusing 'database' with 'schema'. Depending on what was in the dump, you've probably created a load of schema objects and data under the USER schema or whatever your real 'user' value was).
The import makes no difference to this, but if you want to access the database from another client (e.g. from another machine, or over JDBC) then you'll need to check your listener configuration to get the hostname/IP address and port it's listening on, and get the service name for the database; all of which can be obtained from lsnrctl services if you have permission to run that. You can then use those values for a JDBC URL, or in a tnsnames.ora entry, or ODBC, etc.
Look at your ORACLE_SID environment variable. There you'll find the instance ID. If you ran the IMPDP tool as user Oracle, you should also be able to connect to the database using
sqlplus / as sysdba
If all fails, look at your /etc/oratab file to see which instances are available on this host.
On another note, your command seems incomplete. Datapump requires a DIRECTORYparameter to know where to look for the dumpfile you specified.

Error while creating a database in mongodb (not a valid database name in mongo.js)

I am trying to create a database in mongo db using command use db shorten
when i run the mongod instance it outputs this
but when try to run mongo in the separate terminal it gives error creating a database
the data/db permissions are set to 755 and i couldn't find anything related to it
If your db is called 'shorten' you should just type use shorten. It's the extra 'db' in there that's messing you up.

Some beginner's questions about MongoDB

I'm a beginner with MongoDB and I've some questions:
When I'm connected to Mongo, and i execute show dbs I see 2 databases: admin and local. What's their role? Then if I execute an insert command like db.foo.insert({"value":"mongo"}), the test database appears. Why? How can i specify a custom name for a database?
With show dbs I get the databases (somehow like show databases in sql), how can I then list the collections inside a database (I would use show tables in sql)?
When executing a command, the MongoDB tutorial always uses the db object. Is it the main object (a sort of "connection" object) that has to used for executing commands or it's something else?
Thanks!
admin and local contain various settings local to the server, like users who are authenticated to connect. Under beginner usage, you shouldn't need to worry about them at all. By default you connect to a database named test. To connect to a new database, just use databasename from the mongo command line, or mongo databasename from your OS shell.
use [database_name] and then show collections
The db object is your root handle to the currently-selected database on the mongo commmand line. The command line is really just a Javascript command line, and there are various mongodb-specific objects and functions exposed that let you do stuff. Try help() for a full listing.