0

I have the following code that return 0 or no result. I have no running errors

var Users_Collection = new Meteor.Collection("bp_qstat_jobs_monitor_temp");

if (Meteor.isServer) {
   Meteor.startup(function () {
   // code to run on server at startup
   });
}

if (Meteor.isClient) {
   var cursor = Users_Collection.find('j_owner');
   var info = cursor.count();
   console.log(cursor, info);
}

so the question is what I'm doing wrong??? (the collection has 200 records)

Stennie
  • 63,885
  • 14
  • 149
  • 175
juanp_1982
  • 917
  • 2
  • 16
  • 37
  • When you initially load the page, the server has to send the data in the collection, so when you are attempting to find documents, it returns empty as the data you want is not be available on the client yes. Load the page, wait a little bit, then in the JavaScript console run the same query and see what it returns. – 1321941 Jul 17 '14 at 14:06
  • it makes sense what you said, I tried to do what you suggested, I ran cursor = Users_Collection.find({}, {fields: {j_owner: 1}}); but I got an error "ReferenceError: Users_Collection is not defined" if I try to define it, I get another error about collection being used – juanp_1982 Jul 17 '14 at 14:34
  • Remove the var from `var Users_Collection = new Meteor.Collection("bp_qstat_jobs_monitor_temp");` it is because of how the collection is scoped http://docs.meteor.com/#namespacing – 1321941 Jul 17 '14 at 14:42
  • I got this error, Error: There is already a collection named 'bp_qstat_jobs_monitor_temp'. does this mean that when I ran that line in my code, it created a new Collection?!?!?!!??!?! – juanp_1982 Jul 17 '14 at 14:51
  • Sounds like you are trying to define the same collection more than once – 1321941 Jul 17 '14 at 15:03

1 Answers1

0

Usually mongodb will not give error if you are finding the collection which is not available. It will give empty only. Please make sure that you are connected to the correct db, and find the collection.

Check this link for more details.

Community
  • 1
  • 1
msnfreaky
  • 1,013
  • 10
  • 14