有人可以向我解释一下吗?我正在阅读的所有文档都说你只是发出一个use [database]
命令,它会在mongo中创建一个db。
但请看一下:
22:13 $ mongo
MongoDB shell version v3.6.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.0
Server has startup warnings:
2017-12-19T08:36:34.901-0600 I CONTROL [initandlisten]
2017-12-19T08:36:34.901-0600 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-19T08:36:34.901-0600 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-12-19T08:36:34.901-0600 I CONTROL [initandlisten]
> use spiTest
switched to db spiTest
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> db
spiTest
>
当我使用mongodb-core
针对数据库运行测试时,它会抛出错误“Database spiTest doesn't exist
”
如何创建它?
答案 0 :(得分:0)
根据这个我需要先创建一个记录? https://www.mkyong.com/mongodb/how-to-create-database-or-collection-in-mongodb/
> db.users.save( {username:"mkyong"} )
如果这是正确的,那就太傻了。
离开这里希望有更好的答案。