I'm using a book to learn MongoDB. It says that in order to create a db in Mongo, I just need to 'use' it.
show dbs
admin 0.000GB
local 0.000GB
When I do, use someDBName
It says switched to db someDBName
But when I do show dbs
I just see admin and local again. I don't see the someDBName database.
It will not show until your database is empty.
To have your database shown you can use
create collection command to insert collection then it will be shown to you by using
show dbs
Per the MongoDB documentation:
If a database does not exist, MongoDB creates the database when you first store data for that database. As such, you can switch to a non-existent database and perform the following operation in the mongo shell:
use myNewDB
db.myNewCollection1.insertOne( { x: 1 } )
The insertOne() operation creates both the database myNewDB and the collection myNewCollection1 if they do not already exist.
Related
I am running some unit tests using in memory h2 database in spring boot application. Meanwhile interacting with in memory h2 database, I have created some users and grant them some permissions. I can see users are being created successfully (I am assuming it because command gets executed successfully without any issue and grant privileges command also gets executed successfully.). I want to list all existing users that exist in database currently and want to assert results with those users that are created by me.
I know we list all users in mySql database using database query:
select * from mysql.user
I just want to achieve same thing but with in memory h2 database. Does anyone know how can I get list of all users in h2 in memory database.
I am trying this query select * from users but system throws exceptions indicating users table doesn't exist. Is there any way to get all users in h2 database?
I have tried show command but show tables list only those tables that are created by my application. I am not creating any user table myself, I am assuming h2 in memory will have any table persisting users information just like mysql.user table. show schemas also show my database is already created in h2 memory database.
Thank you.
As worked out in comments: you do find the USERS table under the INFORMATION_SCHEMA schema. Therefore you must query:
select * from INFORMATION_SCHEMA.USERS;
The way, DBMS organize their internal configuration is quite different from DBMS to DBMS. In mysql as you stated, there is the users table in mysql.users (at least for MariaDB as far as I know) and for H2 the same is at INFORMATION_SCHEMA.USERS.
I wanted to create a database with the same structure as another database but without restoring data.
Is good idea use Database Configuration Assistant.
Use dbca (Templates )
Create a template for existing database.
Create a database from template
I have a PostgreSql database and I need to connect it to read data from oracle view and store that data in custom table
The PostgreSql database will connect to oracle everyday automatically to read the latest updates from oracle view
How to create it?
It sounds like you probably want a SQL/MED foreign data wrapper. Check out oracle_fdw. You could also use the generic odbc_fdw or jdbc_fdw wrappers via Oracle's ODBC or JDBC drivers.
Another option is DBI-Link.
Combine these with a cron job if you want to copy to a local view.
I have written a set of unit tests using H2 in embedded mode. Whatever changes tests make to DB stay there.
I know that the recommended approach is to create a blank in-memory database and create the schema when opening the connection.
However I am looking for an alternative approach. I would like to -
Initialize an in memory database with an embedded database file.
Or use embedded db in a way that all the changes are discarded as soon as the connection is closed.
How can I achieve this?
What I do in cases similar to this is to write the SQL script that creates the database and populates the tables. Then the application applies a database migration using Flyway DB.
Other possibilities are to create the database and load the tables from CSV files. The other would be to create the database with a different application and create a file with the SCRIPT command to create a backup. Your main application would have to run the RUNSCRIPT command to restore the database.
I use SQL scripts that create tables and other objects and/or populate them, and run these scripts at the beginning of the application.
One could also create a copy of the populated on-disk DB, package it into a ZIP/JAR archive, and open it read only, to be used to recreate and populate the in-memory DB.
I want to create a new database on an Oracle server via JDBC. I cannot seem to connect to the database without providing an SID: using a URL like jdbc:oracle:thin:#//[IP]:1521 results in an error of "ORA-12504, TNS:listener was not given the SID in CONNECT_DATA"
Alternatively, if I log into a specific SID, I can run most DDL commands except for CREATE DATABASE foo which fails with an error of "ORA-01100: database already mounted"
How am I supposed to create a database if I cannot connect to the server without specifying a specific database and cannot create a database if I am already logged into a specific database?
AFAIK creating a database needs an internal and direct connection which can only be done by logging in directly on the server (normally a user account called 'oracle').
One reason for that: users are stored in the database itself. No database = no user to connect to by an external client.
Please also note Justin's comment about oracles database schemas. This is probably what you are looking for
What you need are following commands:
CREATE TABLESPACE CREATE USER and few GRANT ... TO ... -- to have rights to connect and create objects, at least