Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:40:41+00:00 2026-06-01T14:40:41+00:00

Why this code shows 0? Shouldn’t it return 1? Messages = new Meteor.Collection(messages); if

  • 0

Why this code shows “0”? Shouldn’t it return “1”?

Messages = new Meteor.Collection("messages");

if (Meteor.is_client) {
    Meteor.startup(function () {    
        alert(Messages.find().count());
    });
}

if (Meteor.is_server) {
    Meteor.startup(function () {
        Messages.insert({text: "server says hello"});
    });
}

If I do the “Messages.find().count()” later, it returns 1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:40:42+00:00Added an answer on June 1, 2026 at 2:40 pm

    By default, when a Meteor client starts up, it connects to the server and subscribes to documents in any Meteor.Collection you defined. That takes some time to complete, since there’s always some amount of delay in establishing the server connection and receiving documents.

    Meteor.startup() on the client is a lot like $() in jQuery — it runs its argument once the client DOM is ready. It does not wait for your client’s collections to receive all their documents from the server. So the way you wrote the code, the call to find() will always run too early and return 0.

    If you want to wait to run code until after a collection is first downloaded from the server, you need to use Meteor.subscribe() to explicitly subscribe to a collection. subscribe() takes a callback that will run when the initial set of documents are on the client.

    See:

    meteor-publish
    and meteor-subscribe

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to display a grid $('#table1 tr').bind('click', shows); function shows()
I want to display warning messages in html. This code shows two text boxes
This code shows the structure of what I am trying to do. import multiprocessing
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” This code shows warnings
I have this code that shows all the images inside 'images' directory but it
The error shows this code can not rollback: class AddCountToTag < ActiveRecord::Migration def change
This code works in a windows forms application (it shows the preview) but not
I am using this code to access the json data. It shows the two
I have this code, showmessage('C:\TEMP\'+openfiles[openfilelist.ItemIndex].ID); if removedir('C:\TEMP\'+openfiles[openfilelist.ItemIndex].ID) then showmessage('Removed') else showmessage('Failed'); The message shows
I use this code to produce a print-preview window. using (XpsDocument doc = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.