简体   繁体   中英

Getting Users from MongoDb using Node.js

I want to get the users info in my MongoDb using Noe.js. I'm able to get the data from a particular collection with the below code:

 var MongoClient = require('mongodb').MongoClient; var url = "mongodb://localhost:27017/"; MongoClient.connect(url, function(err, db) { if (err) throw err; var dbo = db.db("mydb"); dbo.collection("customers").findOne({}, function(err, result) { if (err) throw err; console.log(result.name); db.close(); }); }); 

In the same manner I want to get the database users (ie admins) details.

Any suggestions ??

Thanks in Advance!!

Regards

Ravi Kumar

 dbo.collection("customers").find()

Will return all users and info from this collection

Note: It will return result as an array

 dbo.collection("customers").count()

Will return how many users are there in collection

There is a database called admin created automatically when you install Mongodb and it contains the admins and their roles for the other databases you can access it via

var dbo = db.db("admin");

use this link https://docs.mongodb.com/manual/tutorial/manage-users-and-roles/#create-a-user-defined-role to learn how to add and manage admins

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM