title: MongoDB with Node.js db queries
body: <p>I want to make an insert in my MongoDB, but it is getting pretty complicated, and it is a simple operation, so I think I am lost at some point.</p>
  
  <p>I have three collections, that I'll simplify for the sake of th question: Sites, Clients, Blacklist.</p>
  
  <p>When a new Client signs up, she instantly gets a Site. Therefore I need to check from the form, if the Client doesn't exist, then if the Client e-mail hasn't been blacklisted, then if the Site doesn't exist, and finally create the elements Client &amp; Site.</p>
  
  <p>I started to do that by callbacks, but it seems overcomplciated for me to do so:</p>
  
  <pre><code>var input = {...}; //assume here I have all the user input
  db.collection('Clients').count({'email', input.email}, {limit: 1}, function (err, count) {
      if (count &gt; 0) {
          db.collection('Blacklist').count({'email', input.email}, {limit: 1}, function (err, count) {
              if (count &gt; 0) {
                  db.collection('Sites').count({'domain', input.domain}, {limit: 1}, function (err, count) {
                      if (count &gt; 0) {
                          // CREATE THE ACCOUNT
                      } else {
                          res.send("Site already exists.");
                      }
                      db.close();
                  });
              } else {
                  res.send("Client is blacklisted.");
              }
              db.close();
          });
      } else {
          res.send("Client already exists.");
      }
      db.close();
  });
  </code></pre>
  
  <p><strong>Any other way to achive this kind of operations with ease?</strong></p>
  
  <p>Ideal for me would be something like:</p>
  
  <pre><code>var input = {...}; //assume here I have all the user input
  if ( db.collection('Clients').count({'email', input.email}, {limit: 1}) == 0 &amp;&amp;
       db.collection('Blacklist').count({'email', input.email}, {limit: 1}) == 0 &amp;&amp;
       db.collection('Sites').count({'domain', input.domain}, {limit: 1}) == 0 ) {
      // INSERT HERE
  } else {
      res.send("Could not insert");
  }
  </code></pre>