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

Time-series collection not working with $where filter

    XMLWordPrintableJSON

Details

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

    Description

      Search for todo after finishing the investigation.

      Attachments

        Activity

          People

            catalin.sumanaru@mongodb.com Catalin Sumanaru
            yuhong.zhang@mongodb.com Yuhong Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: