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

Time-series collection not working with $where filter

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Execution
    • ALL
    • Hide
      > db.getCollection('system.js').insert({     _id: "isTeenager",     value: function(age) {         return age >= 13 && age <= 19;     }, })
      WriteResult({ "nInserted" : 1 })
      > db.createCollection("ts", {timeseries: {timeField: "time"}})
      { "ok" : 1 }
      > db.ts.insert({time: new Date(), name: 'Alice', age: 20})
      WriteResult({ "nInserted" : 1 })
      > db.runCommand({find: "ts", filter: {$where: "isTeenager(this.age)"}})
      {
              "ok" : 0,
              "errmsg" : "$where is not allowed in this context",
              "code" : 2,
              "codeName" : "BadValue"
      }
      > db.foo.insert({name: 'Alice', age: 20})
      WriteResult({ "nInserted" : 1 })
      > db.runCommand({find: "foo", filter: {$where: "isTeenager(this.age)"}})
      {
              "cursor" : {
                      "firstBatch" : [ ],
                      "id" : NumberLong(0),
                      "ns" : "test.foo"
              },
              "ok" : 1
      } 
      Show
      > db.getCollection('system.js').insert({     _id: "isTeenager",     value: function(age) {         return age >= 13 && age <= 19;     }, }) WriteResult({ "nInserted" : 1 }) > db.createCollection("ts", {timeseries: {timeField: "time"}}) { "ok" : 1 } > db.ts.insert({time: new Date(), name: 'Alice', age: 20}) WriteResult({ "nInserted" : 1 }) > db.runCommand({find: "ts", filter: {$where: "isTeenager(this.age)"}}) {         "ok" : 0,         "errmsg" : "$where is not allowed in this context",         "code" : 2,         "codeName" : "BadValue" } > db.foo.insert({name: 'Alice', age: 20}) WriteResult({ "nInserted" : 1 }) > db.runCommand({find: "foo", filter: {$where: "isTeenager(this.age)"}}) {         "cursor" : {                 "firstBatch" : [ ],                 "id" : NumberLong(0),                 "ns" : "test.foo"         },         "ok" : 1 }
    • QE 2024-01-22, QE 2024-02-05, QE 2024-02-19, QE 2024-03-04, QE 2024-03-18, QE 2024-04-01, QE 2024-04-15, QE 2024-04-29, QE 2024-05-13

      Search for todo after finishing the investigation.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            yuhong.zhang@mongodb.com Yuhong Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: