[SOLVED] - How can I get all of fields as an array with meteor and mongodb?

Here is what Users.find({_id: userId}) looks like on Users collection

  "_id" : "123sdasdasd",
  "createdAt" : ISODate("2022-06-15T20:36:01.549+0000"),
  "roles" : {
      "internal" : [
      "client" : [
      "other" : [
  "username" : "sample@gmail.com"

And what I like to do is get all of the fields? on roles

so internal, client and other. I’d like to have them in an array ['internal', 'client', 'other'] like this.

const boardNames = ['internal', 'client', 'other']

I’m trying to do this on client side but if it’s easier I can do on server side as well.

Can I do it?

Assuming that the shape of a user record is as specified above you can do the following.

const user = Meteor.users.findOne({ _id: userId });
const roleTypes = Object.keys(user.roles);
//         ^? const roleTypes: ['internal', 'client', 'other'];
1 Like

This worked perfectly Thank you!