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

Timeseries $geoNear throws unexpected error with lookup

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • Query Integration
    • ALL
    • 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)

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            erin.zhu@mongodb.com Erin Zhu
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: