[SERVER-57561] db.view.find() breaks with --apiStrict Created: 09/Jun/21  Updated: 29/Oct/23  Resolved: 16/Jun/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.0.0-rc0
Fix Version/s: 5.0.0-rc2, 5.1.0-rc0

Type: Bug Priority: Critical - P2
Reporter: Anna Henningsen Assignee: Ruoxin Xu
Resolution: Fixed Votes: 0
Labels: read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.0
Steps To Reproduce:
  • Spin up a 5.0.0-rc0 server
  • Connect with mongosh or mongo and run the steps below:

MongoDB Enterprise replset:PRIMARY> use testdb
switched to db testdb
MongoDB Enterprise replset:PRIMARY> db.source.insertOne({})
{
	"acknowledged" : true,
	"insertedId" : ObjectId("60c088057ddf468ccc60c5e6")
}
MongoDB Enterprise replset:PRIMARY> db.createView('view', 'source', [{$match: {}}])
{
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1623230493, 2),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1623230493, 2)
}
MongoDB Enterprise replset:PRIMARY> db.view.find()
Error: error: {
	"ok" : 0,
	"errmsg" : "BSON field 'aggregate.runtimeConstants' is not allowed with apiStrict:true.",
	"code" : 323,
	"codeName" : "APIStrictError",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1623230493, 2),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1623230493, 2)
}

As you can see, the view is trivial and its aggregation not require any unversioned APIs.

Sprint: Query Optimization 2021-06-28
Participants:

 Description   

A view cannot be accessed with .find() when the connection uses --apiStrict.

Trying do to so results in BSON field 'aggregate.runtimeConstants' is not allowed with apiStrict:true.



 Comments   
Comment by Githook User [ 17/Jun/21 ]

Author:

{'name': 'Ruoxin Xu', 'email': 'ruoxin.xu@mongodb.com', 'username': 'RuoxinXu'}

Message: SERVER-57561 Avoid setting default LegacyRuntimeConstants value when parsing FindCommandRequest

(cherry picked from commit df3417f99795335167ed7251239ab3336b2dfc0c)
Branch: v5.0
https://github.com/mongodb/mongo/commit/d4b437d3977295affd00ed88141c0c2abb180397

Comment by Githook User [ 16/Jun/21 ]

Author:

{'name': 'Ruoxin Xu', 'email': 'ruoxin.xu@mongodb.com', 'username': 'RuoxinXu'}

Message: SERVER-57561 Avoid setting default LegacyRuntimeConstants value when parsing FindCommandRequest
Branch: master
https://github.com/mongodb/mongo/commit/df3417f99795335167ed7251239ab3336b2dfc0c

Comment by A. Jesse Jiryu Davis [ 09/Jun/21 ]

We should include find/aggregate/etc. on views to the list of things we test in mongos_api_params_util.js for sharding coverage. I can help with that if desired.

Comment by Arun Banala [ 09/Jun/21 ]

It looks like find command always sets the runtimeConstants parameter in the parsed object. When we transform the query on the view to an aggregate command, we end up generating an aggregate command with default runtimeConstants values. To circumvent this problem, we should move this code after the above view transformation code.

Ideally, we should replace the usage of runtimeConstants with let (which is allowed in API version 1), but that might not be such a straight forward change.

Comment by Tess Avitabile (Inactive) [ 09/Jun/21 ]

arun.banala charlie.swanson

Generated at Thu Feb 08 05:42:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.