Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-81454

Timeseries $geoNear throws unexpected error with lookup

    • Query Integration
    • Fully Compatible
    • ALL
    • v8.0, v7.3, v7.0, v6.0
    • Hide
      //create a timeseries collection
      assert.commandWorked(testDB.createCollection(tsColl.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
      
      assert.commandWorked(tsColl.createIndex({'tags.loc': '2dsphere'})); 
      
      tsColl.insert({
              time: ISODate(),
              tags: {loc: [40, 40], descr: 0},
              value: 0
          })
      
      const coll2 = db.getCollection("store_min_max_values");
      coll2.drop();
      assert.commandWorked(coll2.insert({_id: 0, minimumDist: 0.0, maximumDist: kMaxDistance}));
      
      
      coll2.aggregate([{$lookup: {from: tsColl.getName(),
      let: {minVal: "$minimumDist",maxVal:"$maximumDist"},
      pipeline: [
      {$geoNear: {near: {type: "Point", coordinates: [0, 0]}, 
                     key: 'tags.loc', 
                     distanceField: "tags.distance"}}],
       as: 'output'}}]);
      
      
      // gives err
      command failed: {
                      "ok" : 0,
                      "errmsg" : "PlanExecutor error during aggregation :: caused by :: $geoNear was not the first stage in the pipeline after optimization. Is optimization disabled or inhibited?",
                      "code" : 40603,
                      "codeName" : "Location40603"
      Show
      //create a timeseries collection assert .commandWorked(testDB.createCollection(tsColl.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}})); assert .commandWorked(tsColl.createIndex({ 'tags.loc' : '2dsphere' })); tsColl.insert({         time: ISODate(),         tags: {loc: [40, 40], descr: 0},         value: 0     }) const coll2 = db.getCollection( "store_min_max_values" ); coll2.drop(); assert .commandWorked(coll2.insert({_id: 0, minimumDist: 0.0, maximumDist: kMaxDistance})); coll2.aggregate([{$lookup: {from: tsColl.getName(), let: {minVal: "$minimumDist" ,maxVal: "$maximumDist" }, pipeline: [ {$geoNear: {near: {type: "Point" , coordinates: [0, 0]}, key: 'tags.loc' , distanceField: "tags.distance" }}], as: 'output' }}]); // gives err command failed: {                 "ok" : 0,                 "errmsg" : "PlanExecutor error during aggregation :: caused by :: $geoNear was not the first stage in the pipeline after optimization. Is optimization disabled or inhibited?" ,                 "code" : 40603,                 "codeName" : "Location40603"
    • CET: Newfie (14 - 20 Nov 23)

      We expect $lookup with $geoNear on a timeseries collection to work as it works on non-timeseries collections. However, $lookup with $geoNear on timeseries is throwing an error. This might be because the geoNear and internalUnpackBucket stages aren't being swapped in optimize when $lookup is used, as it usually is without a $lookup for timeseries.

            Assignee:
            naama.bareket@mongodb.com Naama Bareket
            Reporter:
            erin.zhu@mongodb.com Erin Zhu
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: