[SERVER-29678] collStats should return ok:1 and all fields when the namespace does not exist Created: 15/Jun/17  Updated: 09/Jan/24  Resolved: 02/Jul/18

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: 4.1.1

Type: Improvement Priority: Minor - P4
Reporter: Shane Harvey Assignee: Ben Judd
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-51206 collStats command does not return an ... Closed
Problem/Incident
causes DOCS-13941 collstats command not giving error as... Closed
Related
related to SERVER-36210 Last stable Mongos not abiding by new... Closed
is related to SERVER-51206 collStats command does not return an ... Closed
Backwards Compatibility: Minor Change
Sprint: Storage NYC 2018-07-02
Participants:

 Description   

The "collStats" command on non-existent namespace should be consistent with other commands on non-existent namespaces, and return success (ok:1) and similar to dbStats command should return a document similar in format to that for existing collection but with 0's for sizes.

This will also make the $collStats aggregation stage behave consistently whether only latencyStats or storageStats are requested: currently latencyStats returns a document on non-existent namespace, but storageStats generates an error. There are no other aggregation stages that generate an error on a non-existent collection that I could find.

Original description:
collStats does not return an error code when the database or collection does not exist:

> db.runCommand({collStats: "not-present"})
{
	"ns" : "test.not-present",
	"ok" : 0,
	"errmsg" : "Collection [test.not-present] not found.",
	"operationTime" : Timestamp(1497566635, 1)
}
> db.getSiblingDB("not-present").runCommand({collStats: "not-present"})
{
	"ns" : "not-present.not-present",
	"ok" : 0,
	"errmsg" : "Database [not-present] not found.",
	"operationTime" : Timestamp(1497566645, 1)
}

It should also return an error code, NamespaceNotFound would be a good choice:

> db.runCommand({collStats: "not-present"})
{
	"ns" : "test.not-present",
	"ok" : 0,
	"errmsg" : "Collection [test.not-present] not found.",
	"code" : 26,
	"codeName" : "NamespaceNotFound",
	"operationTime" : Timestamp(1497566635, 1)
}
> db.getSiblingDB("not-present").runCommand({collStats: "not-present"})
{
	"ns" : "not-present.not-present",
	"ok" : 0,
	"errmsg" : "Database [not-present] not found.",
	"code" : 26,
	"codeName" : "NamespaceNotFound",
	"operationTime" : Timestamp(1497566645, 1)
}



 Comments   
Comment by Ben Judd [ 02/Jul/18 ]

Behavior is slightly different, used to return a ok:0 if there was no namespace, now it will return empty/0 result object. However, in the docs behavior in this case is left undefined so no changes are needed.

Comment by Githook User [ 02/Jul/18 ]

Author:

{'username': 'Icantjuddle', 'name': 'Ben Judd', 'email': 'ben.judd@10gen.com'}

Message: SERVER-29678 collStats command returns ok:1, 0-ed response on non-existing namespaces
Branch: master
https://github.com/mongodb/mongo/commit/69feb4a96a2a07d28d1bfd19197c99987dbce9d3

Comment by Ian Whalen (Inactive) [ 07/Jul/17 ]

We believe that the new behaviour should be thus:

  • collStats should return ok:1 for nonexistent namespaces, and provide all the usual fields, with 0's for all the values.
  • This will make it consistent with dbStats, and with $collStats agg stage, regardless of asking for latency or storage stats.

I'll now change the Summary to reflect this.

Comment by Ian Whalen (Inactive) [ 23/Jun/17 ]

Definitely want the command + agg source to be consistent. asya will research whether returning an error code is the correct thing to do in both cases.

Comment by Kyle Suarez [ 16/Jun/17 ]

Given that we've done SERVER-24496, maybe we should just get rid of the command?

Generated at Thu Feb 08 04:21:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.