[DOCS-11098] Docs for SERVER-31885: changeStream cursor is not returned on a mongos when the database does not exist. Created: 08/Dec/17  Updated: 25/Jun/18  Resolved: 22/Jun/18

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: 3.7.1, 3.6.1

Type: Task Priority: Major - P3
Reporter: Kay Kim (Inactive) Assignee: Kay Kim (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-31885 changeStream cursor is not returned o... Closed
Participants:
Days since reply: 5 years, 33 weeks, 5 days ago
Epic Link: DOCS: 4.0 Server
Story Points: 0.1

 Description   

Scope of changes:

Previously, a $changeStream could be opened on a namespace before the associated database had been created. On a replica set, this would produce a valid $changeStream cursor; on a mongoS, however, it would return an empty, closed cursor which could not be used thereafter.

After this commit, a $changeStream can still be opened on a collection that does not yet exist provided that the database does exist. Attempting to open a $changeStream on a non-existent database results in a 'NamespaceNotFound' exception on both replica set and mongoS.

Impact to other docs outside of this product:

MVP:

Resources:

Engineering Ticket Description:

On a replica set a changeStream cursor can be created on a collection where the database does not exist yet:

> db.dropDatabase()
{ "ok" : 1, "operationTime" : Timestamp(1510184057, 1) }
> db.runCommand({"aggregate":"database-does-not-exist", "pipeline":[{'$changeStream': {}}], "cursor": {}})
{
	"cursor" : {
		"firstBatch" : [ ],
		"id" : NumberLong("5437951372965323737"),
		"ns" : "test.database-does-not-exist"
	},
	"ok" : 1,
	"operationTime" : Timestamp(1510184077, 1)
}

The same operation on a mongos does not return a cursor:

MongoDB Enterprise mongos> db.dropDatabase()
{
	"dropped" : "test",
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1510184413, 9),
		"signature" : {
			"hash" : BinData(0,"lFkT1OPozsQoRVqqU/5bXxUNhng="),
			"keyId" : NumberLong("6486191337619062789")
		}
	},
	"operationTime" : Timestamp(1510184413, 9)
}
MongoDB Enterprise mongos> db.runCommand({"aggregate":"database-does-not-exist", "pipeline":[{'$changeStream': {}}], "cursor": {}})
{
	"result" : [ ],
	"cursor" : {
		"id" : NumberLong(0),
		"ns" : "test.database-does-not-exist",
		"firstBatch" : [ ]
	},
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1510184417, 1),
		"signature" : {
			"hash" : BinData(0,"KsuOoKtQYUkl2peKWjMv4kJHzzE="),
			"keyId" : NumberLong("6486191337619062789")
		}
	},
	"operationTime" : Timestamp(1510184417, 1)
}

This is surprising when combined with the fact that wired tiger drops databases when there are no more collections.



 Comments   
Comment by Bernard Gorman [ 22/Jun/18 ]

Hi kay.kim! Yes, this behaviour was changed for 4.0 in SERVER-34138. We didn't backport it, so in 3.6 the database must still exist in order for a change stream to be opened on a non-existent collection.

I've added a DOCS request to SERVER-34138 to clarify the change. Apologies for neglecting to do so at the time the ticket was closed!

Edit: you mention above that the docs currently don't say anything about this behaviour one way or the other. Given that this is a pretty obscure change stream implementation detail, I think it's probably fine to leave it that way.

Comment by Kay Kim (Inactive) [ 14/Feb/18 ]

ravind.kumar – just fyi – this can be done now as the changes are in mongodb 3.6

Generated at Thu Feb 08 08:02:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.