Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. C:mongodbbin>use admin
  2. db.createUser(
  3. {
  4. user: "myUserAdmin",
  5. pwd: "abc123",
  6. roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  7. }
  8. )
  9.  
  10. C:Windowssystem32>mongo
  11. MongoDB shell version v3.4.9
  12. connecting to: mongodb://127.0.0.1:27017
  13. MongoDB server version: 3.4.9
  14. Server has startup warnings:
  15. 2018-03-28T16:53:43.515+0800 I CONTROL [initandlisten]
  16. 2018-03-28T16:53:43.516+0800 I CONTROL [initandlisten] ** WARNING: Access contr
  17. ol is not enabled for the database.
  18. 2018-03-28T16:53:43.516+0800 I CONTROL [initandlisten] ** Read and wri
  19. te access to data and configuration is unrestricted.
  20. 2018-03-28T16:53:43.516+0800 I CONTROL [initandlisten]
  21. 2018-03-28T16:53:43.516+0800 I CONTROL [initandlisten] Hotfix KB2731284 or late
  22. r update is not installed, will zero-out data files.
  23. 2018-03-28T16:53:43.516+0800 I CONTROL [initandlisten]
  24. > show dbs
  25. admin 0.000GB
  26. local 0.000GB
  27. > use admin
  28. switched to db admin
  29. >
  30.  
  31. C:mongodbbin>sc delete MongoDB
  32. C:mongodbbin>mongod --dbpath C:mongodbdata --logpath C:mongodblogMongoDB.log --auth --install
  33.  
  34. C:Windowssystem32>mongo
  35. MongoDB shell version v3.4.9
  36. connecting to: mongodb://127.0.0.1:27017
  37. MongoDB server version: 3.4.9
  38. > show dns
  39. 2018-03-28T17:59:06.344+0800 E QUERY [thread1] Error: don't know how to show
  40. [dns] :
  41. shellHelper.show@src/mongo/shell/utils.js:906:11
  42. shellHelper@src/mongo/shell/utils.js:659:15
  43. @(shellhelp2):1:1
  44. > show dbs
  45. 2018-03-28T17:59:10.073+0800 E QUERY [thread1] Error: listDatabases failed:{
  46. "ok" : 0,
  47. "errmsg" : "not authorized on admin to execute command { listDatabases:
  48. 1.0 }",
  49. "code" : 13,
  50. "codeName" : "Unauthorized"
  51. } :
  52. _getErrorWithCode@src/mongo/shell/utils.js:25:13
  53. Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
  54. shellHelper.show@src/mongo/shell/utils.js:769:19
  55. shellHelper@src/mongo/shell/utils.js:659:15
  56. @(shellhelp2):1:1
  57. >
  58.  
  59. C:Windowssystem32>mongod --auth --port 27017 --dbpath C:mongodbdata
  60. 2018-03-28T16:49:43.874+0800 I CONTROL [initandlisten] MongoDB starting : pid=7
  61. 988 port=27017 dbpath=C:mongodbdata 64-bit host=wolf-PC
  62. .....
  63. 2018-03-28T16:49:43.877+0800 I STORAGE [initandlisten] exception in initAndList
  64. en: 98 Unable to create/open lock file: C:mongodbdatamongod.lock Another program is using this file.... Is a mongod instance already running?, terminating
  65.  
  66. security:
  67. authorization: enabled
  68.  
  69. db.createUser(
  70. {
  71. user: <app db user>,
  72. pwd: <password>,
  73. roles: [ { role: "readWrite", db: <app db> } ]
  74. }
  75. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement