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

Find, update and delete operations in the shell don't support $code

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • ALL

      In the mongo shell (connecting to a 3.6 or a 4.0 mongod), update, delete and find queries don't seem to support the $code type. Insert operations however do allow $code, and all operations do support Code (instead of $code).

      Example:

      Insert works with Code and $code

      vladmac(mongod-3.6.4) test> db.foo.insert({"_id":Code("whatever")})
      Inserted 1 record(s) in 50ms
      WriteResult({
       "nInserted": 1
      })
      

      Delete, update and find work with Code but do not work with $code

      vladmac(mongod-3.6.4) test> db.foo.deleteOne({"_id":{"$code": "whatever"}})
      2018-08-29T15:40:53.500-0400 E QUERY    [thread1] WriteError: unknown operator: $code :
      WriteError({
       "index": 0,
       "code": 2,
       "errmsg": "unknown operator: $code",
       "op": {
         "q": {
           "_id": {
             "$code": "whatever"
           }
         },
         "limit": 1
       }
      })
      WriteError@src/mongo/shell/bulk_api.js:466:48
      Bulk/mergeBatchResults@src/mongo/shell/bulk_api.js:846:49
      Bulk/executeBatch@src/mongo/shell/bulk_api.js:910:13
      Bulk/this.execute@src/mongo/shell/bulk_api.js:1154:21
      DBCollection.prototype.deleteOne@src/mongo/shell/crud_api.js:363:17
      @(shell):1:1
      

            Assignee:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Reporter:
            vladimir.isakov@mongodb.com Vladimir Isakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: