How to populate field before running a geospatial query on it?

Hi, I have a schema, for a vendor and a schema for locations

The vendor has the location model as a reference like so:

const vendorDetailSchema = new mongoose.Schema(
  {
 // som other fields
    locationDetails: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'LocationDetail',
      required: true,
    },
});

The location model is defined like this, with a 2dsphere index included:

const locationDetailSchema = new mongoose.Schema({
  locationType: {
    type: String,
    enum: ['USER', 'VENDOR', 'DELIVERY_ADDRESS'],
    required: true,
  },
  gpsInfo: {
    type: {
      type: String,
      enum: ['Point'],
      required: true,
    },
    coordinates: {
      type: [Number],
      required: true,
    },
  },
  locationName: String,
  locationAddress: String,
  locationGooglePlacesJSON: String, // This is a JSON String from Google Places API
});

locationDetailSchema.index({ gpsInfo: '2dsphere' });

When I try to get the nearest locations directly, I can retrieve them properly…

      const vendors = await LocationDetail.find({
        gpsInfo: {
          $nearSphere: {
            $geometry: {
              type: 'Point',
              coordinates: [userLocation[1], userLocation[0]],
            },
            $maxDistance: 500 * 1000, // kilometers multiplier
          },
        },
      })
        .limit(limit)
        .exec();

However, if I try to populate the data into the VendorDetail model, it throws an error… Is this not possible? If not, how else would one go about sorting location data that is stored in another document?

        const vendors = await VendorDetail.find({
          'locationDetails.gpsInfo': {
            $nearSphere: {
              $geometry: {
                type: 'Point',
                coordinates: [userLocation[1], userLocation[0]],
              },
              $maxDistance: 500 * 1000, // kilometers multiplier
            },
          },
        })
          .populate({
            path: 'locationDetails',
          })
          .limit(limit)
          .exec();

The error message that I get is:
error processing query: ns=test.vendordetailsTree: GEONEAR field=locationDetails.gpsInfo maxdist=500000 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error :: caused by :: unable to find index for $geoNear query

I am assuming this is related to me populating the data… It works fine when directly done on the LocationDetail… Any suggestions how to solve this issue? Thanks!

So… I have been doing some more digging, I think the only way to make this work would be through aggregation… But aggregation also cannot work because the first step in an aggregation pipeline with something like nearSphere would have to be nearSphere, meaning something like

         $lookup: {
           from: 'locationdetails',
           localField: 'locationDetails',
           foreignField: '_id',
           as: 'locationDetails',
         },

to get the data from the location docs wouldn’t work either… So… Hmm is the only choice to actually embed the location directly in the vendorDocument?