title: Using IF/ELSE in MongoDB
body: <p>Can someone help to achieve IF/ELSE in mongoDB? I use below code in SQL Server.</p>
  
  <pre><code>DECLARE @p =1
  IF @p =1
  PRINT @p
  ELSE PRINT "NO"
  </code></pre>
  
  <p>I tried the below codes in MongoDB but could not succeed.<br></p>
  
  <pre><code>var p=1
  { $cond: { if: p=1, then: print(p), else: print("NO") } }
  var p=1
  { $cond: { if: p=1, print(p), print("NO") } }
  </code></pre>