bhok

Untitled

Nov 20th, 2020 (edited)
172
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     let resultBlock;
  2.     const query = {"email":emailAddress};
  3. //    console.log(query)
  4.  
  5.     client.connect(err => {
  6.         const collection = client.db("test").collection("test");
  7.         console.log(client.isConnected());
  8.  
  9.         //Step 1: declare promise
  10.  
  11.         var myPromise = () => {
  12.             return new Promise((resolve, reject) => {
  13.                 client.db("test").collection("test")
  14.                     .find({email: "test@gmail.com"})
  15.                     .limit(1)
  16.                     .toArray(function(err, data) {
  17.                         err
  18.                             ? reject(err)
  19.                             : resolve(data[0]);
  20.                     });
  21.             });
  22.         };
  23.  
  24.         //Step 2: async promise handler
  25.         var callMyPromise = async () => {
  26.  
  27.             var result = await (myPromise());
  28.             //anything here is executed after result is resolved
  29.             return result;
  30.         };
  31.  
  32.         //Step 3: make the call
  33.         callMyPromise().then(function(result) {
  34.             client.close();
  35.             //console.log(result)
  36.             //console.log(result)
  37.         });
  38.  
  39.  
  40.     }); //end mongo client
  41.  
  42.  
  43.  
  44.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×