The Angular-meteor user collection is limited to retrieving only one object at a time

Currently, I am in the process of developing an app using Angular for the front end and Meteor for the back end. My goal is to fetch all users from the "Users" collection (I have integrated the accounts-ui and accounts-password modules). However, when I run the code below, it only retrieves a single object (the most recently added user) despite there being 3 users in total.

if(Meteor.isClient){
angular.module('timeAppApp')
.controller('SignInCtrl', function($scope, $meteor, $location) {

    $scope.LogIn = function() {
        console.log($meteor.collection(Meteor.users).subscribe('users_by_email', $scope.username));
        console.log($meteor.collection(Meteor.users).subscribe('all_users'));
    };

});

}

if (Meteor.isServer) {
    // Retrieves users by email
    Meteor.publish('users_by_email', function(emailE){
        return Meteor.users.find({'emails.address': emailE});
    });

Meteor.publish('all_users', function(){
    return Meteor.users.find({}, {fields: {emails: 1}});
})

As someone new to Meteor, I am still learning and experimenting with different functionalities. At the moment, I am facing a roadblock in this particular scenario.

Answer №1

Give this a shot, From the server side

Meteor.methods({
     fetch_users_by_email: function (emailE) {
         return Meteor.users.find({ emails: { $elemMatch: { address: emailE } } }).fetch();
    }
});

And on the client side

$meteor.call('fetch_users_by_email', $scope.email).then(
            function(data){
                console.log('Successful fetch of users by email', data);
            },
            function(err){
                console.log('Error encountered', err);
            }

        );

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

Firebase Authentication: Invoking `createUserWithEmailAndPassword` triggers `createAuthUri` in case of an error

Whenever a user attempts to create an account with an existing email, calling firebase.auth().createUserWithEmailAndPassword(email, password) results in the error message "QUOTA_EXCEEDED : Exceeded quota for email lookup.". Below is the code sni ...

When it comes to using jQuery, I find that it only functions properly when I manually input the code into the Google Chrome console. Otherwise

Below is the HTML snippet: <textarea cols="5" disabled id="textareRSAKeypair"> @Model["keypair"] </textarea> <a href="#" class="btn btn-primary" id="downloadKeypair">Download Key</a> Here is the jQuery code: <script src="ht ...

Is it possible to make modifications to a file within a docker container without needing to reconstruct the entire image?

Currently working on a large Nodejs microservice with an extensive codebase that isn't my own. My goal is to create and run docker images locally, however I'm encountering failures in the code such as: Error #1: Caused by inserting a /**/ comme ...

Converting a string into a BSON ObjectID

Please help me with this issue: BSON::ObjectId.from_string(params[:_id]) In my journey of learning Sinatra, I encountered the BSON::InvalidObjectId Exception: illegal ObjectId format error and I can't seem to figure out why. Even after passing actual ...

Surprising outcome caused by introducing a service dependency within another service in Angular 6

In my current project, I am facing an issue with ngrx-store and Angular 6. Unfortunately, I cannot replicate the problem on the stackblitz, so I will explain it here. I have a Service1 being used in the component, as well as a Service2 that is used within ...

What could be the reason for express-validator's inability to identify missing fields during the validation of XML input

My server, based on Express, is set up to parse XML instead of JSON using body-parser-xml. To validate the input body, I am using express-validator as shown in the following simplified example: router.post("/", body('session.credential[0].$.usern ...

Keep deciphering in a loop until the URI string matches

I have a task to decode a string URI until there are no more changes. The string URI I am working with typically has around 53,000 characters, so the comparison needs to be fast. For demonstration purposes, I have used a shortened version of the string. B ...

Activate flashlight on web application using JavaScript and HTML through phone's browser

I need help figuring out how to activate a phone's flashlight within a web app using JavaScript and HTML. I successfully developed a web app that scans QR codes using the phone's camera. While I managed to activate the camera, I encountered chall ...

The functionality of Select2 is experiencing issues within the popup of a chrome extension

Encountering an issue with Select2 behavior while using a chrome extension with AngularJS and Angular-UI. The situation Select2's content is being loaded asynchronously through the AngularJs $resouces module. Expected outcome The content should be ...

Convert the number into the following date format: dd/mm/yyyy

The Oracle database has returned the following number: 0.002976190476190476 I want to convert it to the format: dd/mm/yyyy, utilizing either Javascript or jQuery. Any suggestions on how I can achieve this? ...

Update a roster with AJAX following the addition or removal of a user

My goal is to implement two functions: Adding and Deleting a User from the database using Mongoose. However, when I run the code, I receive a 200 OK response but with an empty username. I suspect there might be an issue with the ajax calls. Can anyone hel ...

Switching templates in AngularJS

We have a unique challenge from our client who wants a responsive website, but desires to make significant content changes that may push the limits of bootstrap. Although bootstrap allows for showing/hiding blocks and adjusting their positions with offset ...

Hide the div in PHP if the active variable is null

It looks like I'll need to implement Jquery for this task. I have a print button that should only appear if my array contains data. This is a simplified version of what I'm aiming to achieve: HTML <?include 'anotherpage.php'?> ...

Are there options available in nightwatchjs for making intricate decisions with selectors?

When using the NightWatch JavaScript Selenium tool, it is important to establish good practices for identifying different parts of the GUI before running tests. For example, distinguishing between options A and B and creating separate tests accordingly. An ...

The anchorEl state in Material UI Popper is having trouble updating

I am currently facing an issue with the Material UI popper as the anchorEl state remains stuck at null. Although Material UI provides an example using a functional component, I am working with a class-based component where the logic is quite similar. I w ...

Unable to establish connection with MongoDB replicaSet

While attempting to utilize MongoDB change streams, I encountered an issue with replicaSets. MongoDB does not allow me to use replicaSets due to a load balancer. I tried to disable it using the following configuration: mongodb+srv://${process.env.DB_USERNA ...

Generate a custom JavaScript file designed for compatibility with multiple servers

I am looking to develop a JavaScript file that can be easily added to other websites, allowing them to access functions within my database using an API similar to the Facebook like button. This API should display the total likes and show which friends have ...

Guide on transforming the best.pt model of YOLOv8s into JavaScript

After successfully training a custom dataset on YOLOv8s model using Google Colab, I now have the best.pt file that I want to integrate into a web app via JavaScript. I've come across mentions of TensorFlow.js as a potential solution, but I'm stil ...

Failure to fetch data through Axios Post method with a Parameter Object

I've encountered an issue with Axios while attempting to make a post request with a parameters object to a Laravel route. If I use query parameters like ?username=user, the post request works successfully. However, when I use an object, it fails: Be ...

Protractor end-to-end test for Angular application encounters failure post button click

Today, I've been busy setting up end-to-end testing for an Angular JS application using Protractor. To write more organized tests, I follow the Page Object pattern detailed on the Protractor website. Test Scenario: Upon entering the website, users mu ...