mongo命令行提示符默认只有">", 简单了一点,因为习惯使用mysql的提示符root@localhost:mysql3307.sock [(none)]>,所以想把mongo的提示符也改成这样子,比较方便识别
修改mongorc.js
[keung@isql ~]$ vim ~/.mongorc.js
function prompt() {
var username = "none";
var user = db.runCommand({connectionStatus : 1}).authInfo.authenticatedUsers[0];
var host = db.getMongo().toString().split(" ")[2];
var current_db = db.getName();
if (!!user) {
username = user.user;
}
return username + "@" + host + " [" + current_db + "]> ";
}
连接mongodb测试
[keung@isql ~]$ mongo --host=localhost
MongoDB shell version v3.6.2
connecting to: mongodb://localhost:27017/
MongoDB server version: 3.6.2
none@localhost:27017 [test]> use admin
switched to db admin
none@localhost:27017 [admin]> db.auth("root","password")
1
root@localhost:27017 [admin]>