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

On mongos, cannot query view whose first stage is $collStats and is backed by another view

    • Query
    • ALL
    • Hide
      db.runCommand( { create: "view", viewOn: "collection" } );
      db.runCommand( { aggregate: "view", pipeline: [ { $collStats: {} } ], cursor: { batchSize: 0 } } );
      
      Show
      db.runCommand( { create: "view" , viewOn: "collection" } ); db.runCommand( { aggregate: "view" , pipeline: [ { $collStats: {} } ], cursor: { batchSize: 0 } } );
    • Query 2017-03-27

      In ViewsShardingCheck, we make an assumption that the source namespace of a view must be a collection or a nonexistent namespace. But because of $collStats, it may in fact be a view, and this overeager assumption causes a failure when running a query over a view whose first stage is $collStats and whose "viewOn" is another view.

      mongos> db.createView("v1", "v2", [{: {}}])
      {
              "ok" : 1,
              "logicalTime" : {
                      "clusterTime" : Timestamp(1491580269, 4),
                      "signature" : {
                              "hash" : BinData(0,"TC4eCke2sj28GEb7y236Nspy0ZE="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1491580269, 4)
      }
      mongos> db.createView("v2", "c", [{: {}}])
      {
              "ok" : 1,
              "logicalTime" : {
                      "clusterTime" : Timestamp(1491580277, 1),
                      "signature" : {
                              "hash" : BinData(0,"DYSY4YyCpNPs2tciTcRwkzusMLc="),
                              "keyId" : NumberLong(0)
                      }
              }
      }
      mongos> db.c.insert({x: 1})
      WriteResult({ "nInserted" : 1 })
      mongos> db.c.find()
      { "_id" : ObjectId("58e7b57d102c4c693c576c34"), "x" : 1 }
      mongos> db.v2.find()
      { "ns" : "test.c", "localTime" : ISODate("2017-04-07T15:51:32.358Z") }
      mongos> db.v1.find()
      Error: error: {
              "ok" : 0,
              "errmsg" : "Namespace test.v2 is a view, not a collection",
              "code" : 166,
              "codeName" : "CommandNotSupportedOnView",
              "logicalTime" : {
                      "clusterTime" : Timestamp(1491580293, 1),
                      "signature" : {
                              "hash" : BinData(0,"3GtlKHmzhSsEx1vHk8I0Lz5F5E8="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(0, 0)
      }
      
      Original Description

      When running an aggregation on a view that starts with $collStats and has a batchSize of 0, the following error occurs:

      > db.runCommand( { aggregate: "view", pipeline: [ { $collStats: {} } ], cursor: { batchSize: 0 } } )
      {
              "ok" : 0,
              "errmsg" : "Aggregation has more results than fit in initial batch, but can't create cursor since collection test.view doesn't exist",
              "code" : 17391,
              "codeName" : "Location17391"
      }
      

      Either this should work as expected, or fail with a clearer error message.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            kyle.suarez@mongodb.com Kyle Suarez
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: