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();How to get username on a static page?
-
https://github.com/psychobunny/nodebb-plugin-static-page
I used this example to make a page and wanted to display the username on the page. How do I do that?
-
You wanted the current user's name? If you're using javascript try
app.username
. If you wanted to pass that in from the server side, usereq.user.uid
to call user.getUserFields to pull the username (check out src/routes/user.js line 323-341 for an example)what are you building?
-
I had a slight typo. I had req.user.id