title: Meteor - no more callbacks for "findOne" function
body: <p>i'm working on a Meteor project, and I must say that isn't easy at all, especially for one thing: callbacks !</p>
  
  <p>Everything is async, so I wonder how do I must do to get results from my mongodb.</p>
  
  <pre><code>var user = Meteor.users.findOne({username: "john"});
  return (user); // sometimes returns "undefined"
  </code></pre>
  
  <p>...</p>
  
  <pre><code>var user = Meteor.users.findOne({username: "john"});
  if (user)                    // so ok, I check if it exists!
      return (user);           // Cool, I got my user!
  return ();                   // Ok and what should I return here? I want my user!
  </code></pre>
  
  <p>I don't want to be dirty and put like setTimeout everywhere. 
  Anybody has a solution for this ?</p>
  
  <hr>
  
  <p><strong>EDIT :</strong>
  I noticed in router.js with console.log that my data is returned 4 times. 2 times with an undefined value and 2 other times with the expected value. In the view, it's still undefined.
  Why the router passes like 4 times in this route ? Does it display the first result of the return value in the router ?</p>
  
  <p>What should I return if the find() doesn't find anything ?</p>
  
  <hr>
  
  <p><strong>EDIT 2:</strong> Here is some code to understand.</p>
  
  <pre><code>this.route('profilePage', {
      path: 'profil/:_id?',
      waitOn: function() {
          return [
          Meteor.subscribe('article', { prop: this.params._id}), // id can be id or username
          Meteor.subscribe('article', { userId: this.params._id}), // id can be id or username
          Meteor.subscribe('params'),
          Meteor.subscribe('profil', (this.params._id ? this.params._id : Meteor.userId()))
          ];
      },
      data: function() {
          if (this.params._id) {
              var user = Meteor.users.findOne(this.params._id);
              if (!user)
                  user = Meteor.users.findOne({username: this.params._id});
              console.log(user);
              return user;
          }
          else if (Meteor.userId())
              return Meteor.user();
          else
              Router.go("userCreate");
      }
  });
  </code></pre>
  
  <p>I get this on the console:
  <a href="http://puu.sh/debdJ/69419911f7.png">http://puu.sh/debdJ/69419911f7.png</a></p>
  
  <p>(text version following)</p>
  
  <pre><code>undefined
  undefined
  Object_id: "o3mgLcechYTtHPELh"addresses: (....)
  Object_id: "o3mgLcechYTtHPELh"addresses: (....)
  </code></pre>