简体   繁体   English

如何使用猫鼬在mongodb中创建数据库用户

[英]How to create DB users in mongodb using mongoose

I can create users from mongo shell using createUser() function. 我可以使用createUser()函数从mongo shell创建用户。 but i have a requirement that i need to create users from GUI(using nodej,express).Im using mongoose for multiple connections to db. 但我有一个要求,我需要从GUI创建用户(使用nodej,express)。我使用猫鼬对数据库进行多个连接。 i cant see any functions in mongoose. 我看不到猫鼬的任何功能。 is there any functions or packages that supports features like createUser, delete user like this. 是否有任何支持诸如createUser之类的功能或软件包,像这样删除用户。

connect using db = mongoose.mongo.MongoClient('mongodb://'+username+':'+passwor‌​d+'@localhost/dbtoco‌​nnect, function(err, db){}); 使用db = mongoose.mongo.MongoClient('mongodb://'+username+':'+passwor‌​d+'@localhost/dbtoco‌​nnect, function(err, db){});

using db object get admin access first. 使用db对象首先获取管理员访问权限。 Then you can use admin collection and authenticate using admin username and password using admin_db.authenticate('adminusername', 'password'); 然后,您可以使用admin收集,并使用admin_db.authenticate('adminusername', 'password');使用admin用户名和密码进行身份验证admin_db.authenticate('adminusername', 'password'); using addUser function you can add the users 使用addUser函数可以添加用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用mongoose在mongodb的用户集合中查询一组用户? - How to query for an array of users in my users collection in mongodb using mongoose? 如何使用mongodb(mongoose schema)创建架构? - How to create Schema using mongodb(mongoose schema)? 如何使用mongoDB和mongoose计算2个用户之间的距离 - How to calculate distance between 2 users using mongoDB and mongoose 如何使用 MongoDB (mongoose db) 在聚合中添加 $lookup 填充 - How to add populate with $lookup in aggregate using MongoDB (mongoose db) 如何在mongoose中创建一个新的数据库? - How to create a new db in mongoose? 如何使用Mongoose框架(Mongodb)创建公司和分支机构关系? - How to create company and branch relationship using Mongoose framework(Mongodb)? 如何使用 mongoose ORM 验证在 mongodb 中创建动态模式? - How to create dynamic schema in mongodb with validation using mongoose ORM? 如何使用 mongoose 创建模块以共享不断变化的数据库连接 - How to create a module using mongoose for sharing a changing DB connection 如何使用猫鼬在MongoDB中的日期字段上创建查询? - How to create a query on a Date field in MongoDB using mongoose? 如何在nodejs中使用mongoose在没有任何文档的情况下在mongodb中创建集合 - how to create the collection in mongodb without any document using mongoose in nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM