admin管理员组

文章数量:1125775

I am facing this issue where I have appointments and customers and contacts and while getting an appointment I am using populate to populate the customer from appointment,

The issue is it has been working fine for 3 years but suddenly I am facing an issue where sometimes the populate is returning the customer and sometimes it's returning null, even though data exists in the db.

I am calling it again and again and 4 out of 10 times the populate is returning null.

I tried to find a possible solution couldn't find any, any insight will be helpful.

await this.model.findOne({ _id: appointmentId }).sort({}).select('-_v').populate([
      {
        path: 'customer.customerId',
        model: 'Customers',
        select:
          'vehicles firstName lastName fullNameQBO isFleetCustomer isMFCustomer fleetNumber companyName contactOnEmail contactOnPhone email phone phone2 notes contactId taxExempt preferredLocation',
        populate: {
          path: 'contactId',
          model: 'Contacts',
          select: 'contactInfo',
        },
      },
      {
        path: 'vehicle.vehicleId',
        model: 'Vehicles',
        select: 'year VIN model make engine isActive transmission ODM licensePlateNo vehicleName',
      },
      {
        path: 'estimate.estimateId',
        model: 'RepairOrders',
        select: 'code title estimateBy createdAt vehicle',
      },
    ]).lean(true);

本文标签: nodejsMongoDB populate sporadically not working for same datasetStack Overflow