[SERVER-81454] Timeseries $geoNear throws unexpected error with lookup Created: 26/Sep/23  Updated: 07/Feb/24

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Erin Zhu Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: greenerbuild
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Integration
Operating System: ALL
Steps To Reproduce:

//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"

Sprint: CET: Newfie (14 - 20 Nov 23)
Participants:

 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.


Generated at Thu Feb 08 06:46:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.