I am using a Node.js server and async.js to handle asynchronous callbacks, as well as Mongoose to connect to my Mongo datastore. I am attempting to determine if two object _id's are equal, and if so, execute some code. However, the comparison is not executing correctly. Here's the code:
async.forEachSeries(offerItem.offers, function(currentOfferItemOffer, callback) {
Offer.findById(currentOfferItemOffer, function(err, offerItemOffer) {
if (err) throw err;
console.log(offerItemOffer._id) // 56953639ea526c8352081fdd
console.log(offer._id) // 56953639ea526c8352081fdd
if (offerItemOffer._id !== offer._id) {
console.log('offerItemOffer._id !== offer._id') // Is being logged even though it shouldn't
....
I am very confused as to why a simple comparison like this would not be executing correctly. The code functions as desired when the two _id's are checked for equality using '===' - but this is incorrect logically, as the next block should only be executed when the _id's are not equal. Any thoughts would be greatly appreciated. Thanks!