I am not able to figure out,how to create a database in mongodb. When I login in to the mongo console it shows me test database as default. What are the steps to create a new database?
我无法弄明白,如何在mongodb中创建数据库。当我登录到mongo控制台时,它会将我的测试数据库显示为默认值。创建新数据库的步骤是什么?
2 个解决方案
#1
Whenever we login into mongo without passing any parameter, say db or hostname, it will automatically connect you with test db.
每当我们登录mongo而不传递任何参数时,比如db或hostname,它会自动连接test db。
In order to create DB and dump data from CSV you can use the following command :-
要从CSV创建数据库和转储数据,您可以使用以下命令: -
mongoimport --db nxtshow --collection movies --type csv --file ./mongo/movies.csv --fields id,imdb_url,release_date,title,video_release_date
#2
In MongoDB, to create a database from within the Mongo shell you use
在MongoDB中,要从您使用的Mongo shell中创建数据库
use mydatabasename
where mydatabasename
is the name you want to give to the database. If you want to list the databases
其中mydatabasename是您要为数据库指定的名称。如果要列出数据库
show dbs
The shell quick reference documentation is pretty good.
shell快速参考文档非常好。
For importing data from a CSV file, you can use mongoimport
要从CSV文件导入数据,可以使用mongoimport
#1
Whenever we login into mongo without passing any parameter, say db or hostname, it will automatically connect you with test db.
每当我们登录mongo而不传递任何参数时,比如db或hostname,它会自动连接test db。
In order to create DB and dump data from CSV you can use the following command :-
要从CSV创建数据库和转储数据,您可以使用以下命令: -
mongoimport --db nxtshow --collection movies --type csv --file ./mongo/movies.csv --fields id,imdb_url,release_date,title,video_release_date
#2
In MongoDB, to create a database from within the Mongo shell you use
在MongoDB中,要从您使用的Mongo shell中创建数据库
use mydatabasename
where mydatabasename
is the name you want to give to the database. If you want to list the databases
其中mydatabasename是您要为数据库指定的名称。如果要列出数据库
show dbs
The shell quick reference documentation is pretty good.
shell快速参考文档非常好。
For importing data from a CSV file, you can use mongoimport
要从CSV文件导入数据,可以使用mongoimport