title: Meteor Mongo Not Getting Collection Data
body: <p>I am trying to get a document from a collection, but it doesn't seem to be working.</p>
  
  <p>when i use the find().fetch(), it returns only an empty array. my code is as follows.</p>
  
  <pre><code>var users = new Mongo.Collection("users");
  console.log(users.find());
  var userRecord = users.find().fetch();
  var returnUserRecord = {};
  
  if (userRecord.length &gt;0){
      returnUserRecord = {username:userRecord.username, loginHash:userRecord.loginHash};
      console.log("if statement is not complete and the value of the return variable is");
      console.log(returnUserRecord);
  }
  
  return returnUserRecord
  </code></pre>
  
  <p>I have checked the database directly and noticed that there is indeed a document in the collection with the command: </p>
  
  <pre><code>meteor mongo
  </code></pre>
  
  <p>if it makes any difference, all this code in the in the server js file, and is being called from from the client by: Meteor.Methods()/Meteor.call()</p>
  
  <h2>EDIT 1</h2>
  
  <p>i created another collections with new data from the client, and after selecting the correct database, and running the command:</p>
  
  <pre><code>meteor:PRIMARY&gt; db.newCollection1.find()
  </code></pre>
  
  <p>i get:</p>
  
  <pre><code>{ "_id" : ObjectId("55d1fa4686ee75349cd73ffb"), "test1" : "asdasd", "test2" : "dsadsa", "test3" : "qweqwe" }
  </code></pre>
  
  <p>so this confirms that it is available in the database, but running the following in the client console, still doesnt return the result. (autopublish is installed. i tried removing autopublish and made the appropriate changes to subscribe to the table, but that didnt work either).</p>
  
  <pre><code>var coll = new Meteor.Collection('newCollection1');
  coll.find().fetch()
  </code></pre>
  
  <p>this returned an empty array. i have also tried the same on the server.js code using:</p>
  
  <pre><code>meteor debug
  </code></pre>
  
  <p>but i am still getting an empty array. does anyone know what i might be doing wrong here?</p>
  
  <h2>SOLUTION</h2>
  
  <p>the solution for this was to create the collection variable in the Meteor object context. this way it can be accessed from the Meteor context.</p>
  
  <p>i.e.</p>
  
  <pre><code>Meteor.coll = new Meteor.Collection('newCollection1');
  Meteor.coll.find().fetch();
  </code></pre>
  
  <p>i hope this helps someone. depending on your code you may want to use a different context.</p>