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

A valid $match query fails on time-series collection

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0, 7.0.3, 6.0.12
    • Affects Version/s: 7.1.0-rc0, 7.0.1, 6.0.9
    • Component/s: None
    • Query Integration
    • Fully Compatible
    • ALL
    • v7.0, v6.0
    • Hide
      > db.createCollection("ts", { timeseries: { timeField: "time", metaField: "meta", granularity: "minutes" }})
      > db.ts.insertMany([{time: new Date(), meta: {key: 2, val: 0}, val: 42, key: 1},{time: new Date(), meta: {key: 1, val: 0}, val: 43, key: 1}])
      
      single predicate with non-consts
      > db.ts.aggregate({$match: {$expr: {$lt: ["$meta.val","$val"]}}})
      correctly returns both docs from the collection
      
      two const predicates, combined with $and,
      > db.ts.aggregate({$match: {$expr: {$and: [{$lt: ["$meta.val",42]}, {$eq: ["$meta.key",1]}]}}})
      correctly returns one matching doc from the collection
      
      two predicates, one of them non-const
      > db.ts.aggregate({$match: {$expr: {$and: [{$lt: ["$meta.val","$val"]}, {$eq: ["$meta.key",1]}]}}})
      raises error:
      "errmsg" : "Failed to optimize pipeline :: caused by :: createComparisonPredicate() does not handle metadata predicates: 0xAAAB14AD4640",
      "code" : 6707200
      
      two non-const predicates, split across two $match stages
      > db.ts.aggregate([{$match: {$expr: {$lt: ["$meta.val","$val"]}}}, {$match: {$expr: {$eq: ["$meta.key","$key"]}}}])
      correctly returns one matching doc from the collection
      
      Show
      > db.createCollection( "ts" , { timeseries: { timeField: "time" , metaField: "meta" , granularity: "minutes" }}) > db.ts.insertMany([{time: new Date(), meta: {key: 2, val: 0}, val: 42, key: 1},{time: new Date(), meta: {key: 1, val: 0}, val: 43, key: 1}]) single predicate with non-consts > db.ts.aggregate({$match: {$expr: {$lt: [ "$meta.val" , "$val" ]}}}) correctly returns both docs from the collection two const predicates, combined with $and, > db.ts.aggregate({$match: {$expr: {$and: [{$lt: [ "$meta.val" ,42]}, {$eq: [ "$meta.key" ,1]}]}}}) correctly returns one matching doc from the collection two predicates, one of them non- const > db.ts.aggregate({$match: {$expr: {$and: [{$lt: [ "$meta.val" , "$val" ]}, {$eq: [ "$meta.key" ,1]}]}}}) raises error: "errmsg" : "Failed to optimize pipeline :: caused by :: createComparisonPredicate() does not handle metadata predicates: 0xAAAB14AD4640" , "code" : 6707200 two non- const predicates, split across two $match stages > db.ts.aggregate([{$match: {$expr: {$lt: [ "$meta.val" , "$val" ]}}}, {$match: {$expr: {$eq: [ "$meta.key" , "$key" ]}}}]) correctly returns one matching doc from the collection

      The same query executes fine on a non-time-series collection with the same inserted documents. The error is specific to the predicates re-write we do for time-series.

            Assignee:
            gil.alon@mongodb.com Gil Alon
            Reporter:
            irina.yatsenko@mongodb.com Irina Yatsenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: