Leveraging UnderscoresJS _.pluck function in conjunction with the Meteor users database

Currently facing an issue with the _.pluck function in Meteor. I have successfully set up a subscription to the users collection and confirmed that all users are being fetched by using console.log. However, when attempting to use _.pluck(users, 'username'), I encounter an error message in the console -

TypeError: Cannot read property 'username' of null.
. Below is the code snippet:

MattersController.helpers({
  'matterAccess': function(access) {
    if (access) {
      var users = Meteor.users.find({}, { fields: {'username': 1}});
      // console.log(users);
      var usernames = _.pluck(users, 'username');
      console.log(usernames);
    } else {
      return;
    }
  }
});

It's worth noting that the access parameter is returning true.

Answer №1

When using the "find" method, it returns a cursor instead of an actual array. To convert it to an array, you can utilize the fetch() function.

var users = Meteor.users.find({}, { fields: {'username': 1}}).fetch();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting up only two input fields side by side in an Angular Form

I'm fairly new to Angular development and currently working on creating a registration form. I need the form to have two columns in a row, with fields like Firstname and Lastname in one row, followed by Phone, Email, Password, and Confirm Password in ...

Using NodeJS and Express: redirection fails to load the specified endpoint

My current project involves a simple e-commerce web application running on localhost built with nodejs and express. Admins are required to register in order to gain access to functionalities such as adding, editing, and removing products from the product l ...

Array in JavaScript containing a replica set of Node.js and MongoDB

As a novice programmer with more experience in sysadmin work, I've been tasked with setting up a new HA environment for a node js application using MongoDB. The current setup utilizes mongojs and monq java classes with only one MongoDB instance. In or ...

Issues with removing options from Autocomplete persist in React MaterialUI

Currently navigating the world of ReactJS and experimenting with Material UI's Autocomplete component. The challenge lies in managing a complex data structure where options are dynamically generated based on user selections, but removing previously se ...

The React component designed to consistently render video frames onto a canvas is unfortunately incompatible with iOS devices

I'm facing an issue with my code snippet that is supposed to draw video frames on a canvas every 42 milliseconds. It's working perfectly on all platforms and browsers except for iOS. The video frames seem unable to be drawn on canvas in any brows ...

Node.js encountering req.body as undefined when using form-data as the content-type

After creating a small demonstration for this form-data passing API, I attempted to test it using Postman. However, I encountered an issue where no data was being retrieved. Code const http = require("http"); const express = require("expres ...

Showcase the latest added entry in Meteor

Managing a form and list of objects on the same page can be challenging, especially when it comes to identifying newly inserted rows. One solution could be to color or highlight these rows temporarily to make them stand out. Afterwards, the highlight could ...

Using Webdriver to dynamically enable or disable JavaScript popups in Firefox profiles

I am currently working on a test case that involves closing a JavaScript popup. The code functions correctly in a Windows environment, but when I try to deploy it on a CentOS based server, I encounter the following error: Element is not clickable at point ...

Unable to change background color in iPhone layout

My attempt to change the header's background color is successful in desktop layout, but not working as expected on iPhone. The header color remains unchanged in the iPhone layout. Below is my code snippet: http://jsfiddle.net/mzMjT/embedded/result/ ...

Customizing CoreUI column names in Vue

I am working with an array of item objects for a table. For example: [{ name: 'Sam', age: 24 }] Instead of using the default column names like age, I want to set custom field names. For instance, I want to display the column as Id instead of age ...

Position the model in the center of the scene using three.js

Currently, I am utilizing the code below to center an object within the scene. While it works perfectly with the json loader, the issue arises when using either OBJLoader or OBJMTLLoader. function modelLoadedCallback(geometry, materials) { // Create ...

What steps can I take to locate the Angular version within my project?

After setting up the Angular code on my local machine, I am now eager to find out the version of Angular used in the project. Can someone please share a convenient method to locate this information within the command prompt? ...

Testing the dispatching of a custom event in a method

I am facing an issue with a static method I have that is responsible for creating a custom event and dispatching it: class MyComponent extends { static refreshComponent() { const event = new Event('refreshComponent'); ...

Adjust the color of an item when scrolling

I am trying to create an object that changes color after scrolling 100px down and reverts back to its default color when scrolling back up. I have tried using this code, but it is not working properly: Here is the jQuery code snippet: $(window).scroll(fu ...

Activate an asynchronous request within a dropdown menu that was loaded using ajax

Let me start by presenting a simplified version of my code: HTML : <form id="add"> <select id="cat"> <option selected value="">…</option> <option value="a">A</option> <option value="b"& ...

AngularJS Accordion Component: A Handy Tool for Organ

I have been trying to implement an Accordion in my angular project by sending HTML structure from a controller. However, despite following the documentation closely, the Accordion is not displaying as expected. Here is a snippet of the code I am using: v ...

How can one accurately pair the key and its corresponding value from an array of objects to create a new object containing only that key?

In my JavaScript code, I am attempting to create a function that can match a specific key with an array of objects fetched from an API. This matching process is based on two parameters obtained from the API: a key (which is a string) and an array of object ...

Is it possible to create a new field in mongoDB from a separate collection without any dependencies?

I manage two different sets of data: profiles and contents The profiles collection is structured as follows: { _id: ObjectId('618ef65e5295ba3132c11111'), blacklist: [ObjectId('618ef65e5295ba3132c33333'), ObjectId('618ef65e5295 ...

Solution: "The Mongoose Model.find method consistently provides an empty result set."

Currently, I am utilizing mongoose in combination with next.js to interact with an existing collection. Despite the collection not being empty, the mongoose model.find() function consistently returns an empty array. Below is my model code: const mongoose ...

My attempt at automatically submitting the form using jQuery to the ajax function was unsuccessful, and no error messages were displayed

I've been experimenting with different approaches to solve this issue for the past two hours, but haven't had any luck yet. It's frustrating :( I am currently working on creating new form elements using values generated from JSON and a jQue ...