Guest User

Missing document properties!

a guest
Nov 11th, 2025
27
0
179 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.45 KB | Software | 0 0
  1.     while ( archiverCount > 0 ) {
  2.         messages
  3.          .find( )
  4.          .where('state').equals('REMOTE')
  5.          .where('is_spam').equals(false)
  6.          .where('spam_score').lte(MAX_SPAM_SCORE)
  7.          .where('deliveryAttempts').lte(MAX_DELIVERY_ATTEMPTS)
  8.          .where('nextDeliverAttempt').equals(null)
  9.          .sort( ARCHIVE_SORT )
  10.          .exec( )
  11.          .then( async (msgDoc) => {
  12.             if ( msgDoc === null || msgDoc === undefined ) {
  13.                 log.error('msgDoc provided in .then() is NULL!');
  14.                 console.error('[' + getTimestamp() + '] msgDoc provided in .then() is NULL!');
  15.                 // By calling return this early in the async function, we're essentially calling
  16.                 //  'continue' to iterate through the while() loop again.
  17.                 return false;
  18.             }
  19.  
  20. console.debug('msgDoc (inside while() loop): ' + JSON.stringify(msgDoc));
  21.             logEntry = '[' + getTimestamp() + '] Beginning message archival process (id: ' + msgDoc._id + ').';
  22. //
  23. // W-T-F ??
  24. // The call to console.debug() that references 'msgDoc' /sees/ the document and all of
  25. //  it's properties; but then by the /very next/ line, accessing one of those properties
  26. //  (the '_id' property) returns undefined.
  27. //
  28. console.debug(logEntry);
  29. console.debug('msgDoc: ' + JSON.stringify(msgDoc));
  30. console.debug('msgDoc._id: ' + msgDoc._id);
  31.             res = await messages
  32.              .updateOne({'_id': msgDoc._id},
  33.              {
  34.                 '$push': { 'Log': logEntry },
  35.                 '$currentDate': { 'lastUpdated': { '$type': 'date' }}
  36.              })
  37.              .exec();
  38.             if ( res.modifiedCount != 1 ) {
  39.                 // modifiedCount should NEVER be greater than 1 (since we called findOne()
  40.                 //  nor should it ever be zero; in either case, something is awry.
  41.                 console.log('[' + getTimestamp() + '] messages.updateOne() modified count != 1: ' +
  42.                     res.modifiedCount + '.');
  43.                 log.info('[' + getTimestamp() + '] messages.updateOne() modified count != 1: ' +
  44.                     res.modifiedCount + '.');
  45.  
  46.                 dbLog.create({
  47.                     'application': APP_NAME_FULL,
  48.                     'ts': Date.now(),
  49.                     'host': fqdn,
  50.                     'pid': process.pid,
  51.                     'message': 'messages.updateOne() modified count != 1 (value: ' + res.modifiedCount + ')'
  52.                 });
  53.             }  
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment