Receiving an ambiguous message from the meteor subscriptions

New to using Meteor, I am trying to create a registration form with Meteor. I am facing some challenges with the `findOne` and `subscribe/publish` functions. Here is my `collection.js` file:

User_Customer = new Meteor.Collection("USER_CUSTOMER");
Customer = new Meteor.Collection("CUSTOMER");

This is my `publish.js` file in the `/server` directory:

Meteor.publish("CUSTOMER", function() {
    return Customer.find();
});

Meteor.publish("USER_CUSTOMER", function() {
    return User_Customer.find();
});

And here is the function I have created to subscribe and find items in the `/client` directory:

function isAvailableForUserRegister(email, identity, phone){
    Meteor.subscribe("CUSTOMER", function(){
        var cust = null;
        cust = Customer.findOne({Identity: identity});
        if(cust != null){
            Meteor.subscribe("USER_CUSTOMER", function(){
                var uc1 = null;
                uc1 = User_Customer.findOne({Email: email});
                if(uc1 != null){
                    var uc2 = null;
                    uc2 = User_Customer.findOne({Phone: phone});
                    if(uc2 != null)
                        return true
                    else
                        return false;
                }else return false;
            });
        }else return false;
    });
}

The `isAvailableForUserRegister` function checks if an email, identity, or phone number already exist in the collections:

Identity in Customer
Email in User_Customer
Phone in User_Customer

The issue I am facing is that the process does not continue to enter the second subscription, as the `cust` variable has an `undefined` value. I have tried debugging with Chrome, but still unable to find a solution. Can anyone help me resolve this function?

Thank you.

Answer №1

It seems like an asynchronous issue, the subscription is not yet ready. You can attempt the following solution:

Meteor.subscribe("CUSTOMER").ready();
Meteor.subscribe("USER_CUSTOMER").ready();

Answer №2

Make sure to only use Meteor.subscribe once within the client.

Code for the client:

Meteor.subscribe("CUSTOMER");
Meteor.subscribe("USER_CUSTOMER");

function checkAvailabilityForUserRegistration(email, identity, phone){
  var customer = Customer.findOne({Identity: identity});
  if(customer === null) {
    return false;
  }
  var userCustomer = User_Customer.findOne({$or: [
    {"Email": email}, 
    {"Phone": phone}
  ]);
  return userCustomer !== null;                
}

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

Retrieve worldwide data for the entire application in Next.js during the first page load

Within my Next.js application, I am implementing search filters that consist of checkboxes. To display these checkboxes, I need to retrieve all possible options from the API. Since these filters are utilized on multiple pages, it is important to fetch the ...

Retrieve webpage using HTML stored in web storage

I am exploring a new idea for an application that utilizes local storage, and I am seeking guidance on the most effective way to load content after it has been stored. The basic concept of the app involves pre-fetching content, storing it locally, and the ...

Submit simple text via XMLHttpRequest to an Express server

I am currently facing an issue with making a post XMLHttpRequest to my Express server. Despite attempting to send a string, it seems that I am missing something crucial in my implementation. Client: const sendMessage = () => { const message = "This ...

Using Formik with MUI Multiple Select

Exploring the world of MUI and Formik, I encountered a challenge with creating a multiple Select in my form. It's my first time working with these tools, so I have a question regarding the implementation. Here's what I've tried based on the ...

Using various jQuery autocomplete features on a single webpage

UPDATE I have observed that the dropdown elements following the initial one are not being populated correctly. .data( 'ui-autocomplete' )._renderItem = function( ul, item ) { return $( "<li></li>" ) .data( "i ...

Emphasize the designated drop zone in Dragula

Incorporating the Dragula package into my Angular 2 project has greatly enhanced the drag-and-drop functionality. Bundling this feature has been a seamless experience. Visit the ng2-dragula GitHub page for more information. Although the drag-and-drop fun ...

Not adhering to directive scope when transclusion is used, despite explicit instructions to do so

Trying to use a transcluding directive within another controller, but the inner scope isn't being redefined as expected. Despite trying different methods, I can't seem to figure out what's going wrong. The simplified code looks like this: ...

Create a dynamic onClick event script and integrate it into Google Optimize

I need to incorporate a button element into my website using Google Optimize for an experiment. This button needs to trigger a specific script depending on the variation of the experiment. I have attempted two different methods: <button id="my-button" ...

In Node.js Express, the download window won't pop up unless the entire file has been sent in the header response

I have been using Express to develop an API that allows users to download PDF files. The download process is functioning correctly, but I am facing an issue where the download window, which prompts me to select a destination folder for the download, only a ...

Preventing the detection of a jshint "error"

When creating an object using the constructor X, I later add multiple methods in the file using X.prototype.method = function () {...}. Although technically an assignment statement, it behaves like a function declaration, which typically doesn't requi ...

Saving JSON format in VueX State Management

I'm relatively new to using Vue/VueX and I am exploring methods for storing JSON data in the VueX state. Initially, it seemed like a simple task: state { jsonthing: { ... } } However, I encountered an issue where getters return an Observer type ins ...

Verify user identities using just their passwords

For my express app, I'm tasked with creating an authentication system that uses a 4-digit pin as the password. The code is set up to save and hash the pin along with other user information when adding a new user. Since this is for an in-house server h ...

Add a fresh column in the table that includes modified values from an existing column, affected by a multiplication factor provided through a text input

I'm currently working on a Laravel website where I have a pricing table sourced from a database. The Retail Price column in this table serves as the base for calculating and populating a Discount Price column using a multiplier specified in a text inp ...

ReactJS - Error: Attempting to access the property 'raw' of an undefined variable

I'm currently facing an issue where I am trying to extract specific data from a particular part of an api. Surprisingly, I can view all the data in the console. { "id":"DszAeHV8zfQ", "created_at":"2020-01-28T19:41:06-05:00", "updated_at":"2020 ...

How can I trigger a function by clicking on a link that was generated dynamically with jQuery?

I am dynamically creating multiple <a href="#"></a> elements with dynamically assigned id attributes like <a href="#" id='delete"+id+"'></a>. The IDs generated will be like delete01, delete02, .... I want to trigger a func ...

What is the best way to deploy a REST API utilizing an imported array of JavaScript objects?

I have been using the instructions from this helpful article to deploy a Node REST API on AWS, but I've encountered a problem. In my serverless.yml file, I have set up the configuration for the AWS REST API and DynamoDB table. plugins: - serverless ...

Explore a JSON array within another JSON array

Here is a JSON format that I have: { "Project [id=1, dateDebut=2017-01-13, dateFin=2017-01-18, description=qsd, sponsor=qsd ]" : [ {"id":1,"title":"qsd ","description":"qsdqsd","dateFin":"2017-01-26"}, {"id":2,"title":"sss ","descriptio ...

What are some recommended methods in Angular for developing reusable panels with both controller and view templates?

I am still getting acquainted with angularjs, so there might be something I'm overlooking, but I'm struggling to find an efficient way to create reusable views that can be instantiated within a parent view. My specific scenario involves a web ap ...

Tips for accessing $parent of ng-repeat from ng-include

In my code, I have a nested ng-repeat structure with an ng-include inside the inner ng-repeat. I am trying to access the outer ng-repeat using $parent within the ng-include. Here is an example of what I am working on: index.html <div ng-repeat="popula ...

The Javascript code is not running due to the XSS security measures in place

Within my Wordpress website, I have crafted an HTML form that enables users to view database records corresponding to their input. Following this AJAX tutorial on w3schools, a JavaScript function was implemented to send a GET request to a PHP script on the ...