I found a good way to get the user list out of mongodb. In case anyone need it:
async function doMongoDb() { const { MongoClient } = require("mongodb"); const username = encodeURIComponent("admin"); const password = encodeURIComponent("mypassword"); const clusterUrl = "localhost:27017"; const authMechanism = "DEFAULT"; const uri = `mongodb://${username}:${password}@${clusterUrl}/?authMechanism=${authMechanism}`; const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true }); try { await client.connect(); const database = client.db("nodebb"); const objects = database.collection("objects"); // get all user const query = { _key: /^user:\d+$/ }; // select fields we want to see const options = { projection: { _id: 0, username: true, _id: false, email: true, "email:confirmed": true, joindate: true, fullname: true }, }; const cursor = objects.find(query, options); if ((await cursor.count()) === 0) { console.log("No user found!"); } // iterate over the users await cursor.forEach(user => { if (user["email:confirmed"] == 1 ) { console.dir(user); } }); } finally { // make sure we close the connection await client.close(); } } // --------------------------------------------------- function init() { try { doMongoDb(); } catch(e) { console.log(e); } } // --------------------------------------------------- init();Help pulling user info
-
i want to make a menu for my home that has avatar, name, post count and reputation of the user logged in.
For some reason i just cant figure out how to do that, is there any global shortcodes or anything? -
does this help? http://community.nodebb.org/api/user/psychobunny
-
to get current user's name,
app.username
. then its just a simple matter of doing something like $.get -
O.o Interesting. @psychobunny thanks.
-
How about the same thing but for groups?
I need to find the gid of the admin group, is there a nice simple way of doing that? -
Not on the client side, but on server-side, you can run this:
var Groups = require('./groups'); Groups.getGidFromName('Administrators', function(err, gid) { console.log('admin group gid is', gid); });
getByGroupName
will also return the group object -
@julian Thanks. I was using that last night but i was trying client side and couldnt figure out why it wasnt working
-
Right-o -- group management is restricted to admin only, hence there are no public API endpoints for it.
If you are an admin, try this route:
/api/admin/groups
-
I feel like getting group membership should be publically available, so we could write a groups page for example, or give users labels depending on who they are. (ex. coloured username / badge for admins)
-
@julian
Got it with thissocket.emit('admin.groups.get', gid, function(err, groupObj) { });
Works like a charm.