问题描述
我在 mac 上本地安装。根据 MongoDB 文档创建具有 root 权限的用户超级用户:https://docs.mongodb.com/guides/server/auth/#procedure
char[]
启动它
#include <iostream>
#include <string>
using namespace std;
class Autor {
string name;
string surname;
public:
Autor()
: name("-"),surname("-")
{
}
Autor(const string& nam,const string& surnam)
: name(nam),surname(surnam)
{
if (name.empty()) name = "-";
if (surname.empty()) surname = "-";
}
string getName() const { return name; };
string getSurname() const { return surname; };
Autor& setName(const string& nam) {
name = nam;
if (name.empty()) name = "-";
return *this;
}
Autor& setSurname(const char* surnam) {
surname = surnam;
if (surname.empty()) surname = "-";
return *this;
}
void print1() const {
cout << "First print type: " << name << " " << surname << "\n";
}
void print2() const
{
cout << "Second print type: " << "Author,name: " << name << "\n";
}
};
class Book {
string name;
string codeUDK;
Autor auth;
int year;
int numPages;
public:
Book()
: name("x"),codeUDK("x"),auth("x","x"),year(0),numPages(0)
{
}
Book(const string& nam,const string& code,const Autor &a,int yea,int numP)
: name(nam),codeUDK(code),auth(a),year(yea),numPages(numP)
{
if (name.empty()) name = "x";
if (codeUDK.empty()) codeUDK = "x";
}
string getName() const { return name; }
string getCode() const { return codeUDK; }
Autor& getAuth() { return auth; }
const Autor& getAuth() const { return auth; }
int getYear() const { return year; }
int getNumPages() const { return numPages; }
Book& setName(const string& nam)
{
name = nam;
if (name.empty()) name = "x";
return *this;
}
Book& setCode(const string& code)
{
codeUDK = code;
if (codeUDK.empty()) codeUDK = "x";
return *this;
}
Book& setAuth(const Autor &a)
{
auth = a;
return *this;
}
Book& setYear(int yea)
{
year = yea;
return *this;
}
Book& setNumPages(int num)
{
numPages = num;
return *this;
}
void print1() const {
cout << "First print type: " << name << " code: " << codeUDK << " author's name: " << auth.getName() << " author's surname: " << auth.getSurname() << " year of writing " << year << " amount of pages: " << numPages << "\n";
}
void print2() const {
cout << "Second print type: " << "Book,name and author: " << name << ",Author: " << auth.getName() << auth.getSurname() << "\n";
}
};
int main()
{
string nameA,surnameA;
cout << "enter name and surname: ";
cin >> nameA >> surnameA;
Autor auth(nameA,surnameA);
Autor auth1(auth);
auth.print1();
auth.print2();
cout << "\ncopied author:\n";
auth1.print1();
auth1.print2();
Book myBook("1984","23481-b",auth,1896,234);
myBook.print1();
myBook.print2();
return 0;
}
导致运行mongodb实例:
> db.createuser({user:"superuser",pwd:"strongPassword",roles:["root"]})
Successfully added user: { "user" : "superuser","roles" : [ "root" ] }
> show users
{
"_id" : "admin.superuser","userId" : UUID("f873bafd-8d9b-4d2d-95a2-95d9e05db25d"),"user" : "superuser","db" : "admin","roles" : [
{
"role" : "root","db" : "admin"
}
],"mechanisms" : [
"SCRAM-SHA-1","SCRAM-SHA-256"
]
}
然后我
"ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
回复: mongo --port 27017
这是踢球者:
我输入
use admin
然后
switched to db admin
请帮帮我?我的问题在这里似乎很简单。完全遵循 mongoDb 文档,然后完全没有看到我的用户。这里有什么技巧?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)