阅读更多
> use admin
switched to db admin
> db.createUser({user:“root”,pwd:“pass”,roles:[{role:“userAdminAnyDatabase
”db.createUser({user:“root”,pwd:“pass”,roles:[{role:“userAdminAnyDatabase
”,db:“admin”}],mechanisms:[“SCRAM-SHA-1”]})
2019-07-17T10:59:00.894+0800 E QUERY [js] SyntaxError: illegal character @(sh
ell):1:20
> db.createUser({user:“root”,pwd:“pass”,roles:[{role:“userAdminAnyDatabase
”db.createUser({user:“root”,pwd:“pass”,roles:[{role:“userAdminAnyDatabase
”,db:“admin”}],mechanisms:[“SCRAM-SHA-1”]})
2019-07-17T10:59:20.478+0800 E QUERY [js] SyntaxError: illegal character @(sh
ell):1:20
> db.createUser({user:"root",pwd:"pass",roles:[{role:"userAdminAnyDatabase",db:"
admin"}],mechanisms:["SCRAM-SHA-1"]})
Successfully added user: {
"user" : "root",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1"
]
}
> whereis mongod
2019-07-17T11:02:56.375+0800 E QUERY [js] SyntaxError: missing ; before state
ment @(shell):1:8
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> show users;
{
"_id" : "admin.root",
"userId" : UUID("2afa70f7-c5c5-4738-b187-6208d2cdca1c"),
"user" : "root",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1"
]
}
> db.runoob.insert({"name":"new chapt 1"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> db.admin.insert({"name":"see tomorrow"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> show tables
admin
runoob
system.users
system.version
> select * from admin
2019-07-17T11:15:18.071+0800 E QUERY [js] SyntaxError: missing ; before state
ment @(shell):1:14
> db.collection.find().pretty()
> db.admin.find().pretty()
{ "_id" : ObjectId("5d2e92a8f50738b56bf09a93"), "name" : "see tomorrow" }
>
创建用户,建表,查询。
基本任务完成。
照着搞吧。
https://www.runoob.com/mongodb/mongodb-query.html