Mongoose Aggregate Read Preference and Max Staleness Time

Viewed 35

I am trying to ensure a max staleness time for mongoose aggregates if I am using a secondary cluster. I want it to be 300 seconds, because we can afford for our data to be stale, but not very stale. After reading the mongoose docs, I could only find out how to set our read preference to the secondary cluster. Is there anything I can do to set the maxStaleTime of the secondary cluster in my aggregate call?

Here is what I have so far.

  const textMessagesIncomingAfterHours = TextMessage.aggregate([
    {
      $match: tenantQuery
    },
    {
      $project: {
        dayOfWeek: {
          $dayOfWeek: {
            date: {
              $toDate: "$timestamp"
            },
            timezone: timezone
          }
        },
        hour: {
          $hour: {
            date: {
              $toDate: "$timestamp"
            },
            timezone: timezone
          }
        },
        patientIds: "$patientIds",
        _tenant: "$_tenant",
        direction: "$direction",
        patientPhoneNumber: "$patientPhoneNumber",
        timestamp: "$timestamp"
      }
    },
    {
      $match: incomingTextsAfterHoursQuery
    }
  ]).read("secondaryPreferred");
0 Answers
Related