Wednesday, 5 April 2017

Mongoose Promise do not return expected object

I execute a MongoDB request to get document and return a value which is not taken into account.

// Exec request
return MDBObject.find({}, (err, objectsMongoDB) => {
  var objectMongoDB = null;
  if (err) {
    return Promise.reject(err);
  } else {
    // Check
    if (objectsMongoDB && objectsMongoDB.length > 0) {
      objectMongoDB = objectsMongoDB[0];
    }
    // Ok
    return objectMongoDB;
  }
}

Thanks!

Regards, Serge.



via Serge

No comments:

Post a Comment