[DRIVERS-2210] Fix server version incompatibility for updateOne-let and updateMany-let server-side error tests Created: 16/Feb/22  Updated: 14/Apr/23  Resolved: 14/Apr/23

Status: Closed
Project: Drivers
Component/s: CRUD
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Dmitry Rybakov
Resolution: Done Votes: 0
Labels: yaml-test
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Issue split
split to CSHARP-4059 Fix server version incompatibility fo... Closed
split to CXX-2455 Fix server version incompatibility fo... Closed
split to GODRIVER-2313 Fix server version incompatibility fo... Closed
split to MOTOR-898 Fix server version incompatibility fo... Closed
split to NODE-4013 Fix server version incompatibility fo... Closed
split to PYTHON-3129 Fix server version incompatibility fo... Closed
split to RUBY-2910 Fix server version incompatibility fo... Closed
split to RUST-1188 Fix server version incompatibility fo... Closed
split to PHPLIB-748 Support 'let' option for multiple CRU... Closed
split to JAVA-4497 Fix server version incompatibility fo... Closed
split to CDRIVER-4198 Support 'let' option for multiple CRU... Closed
Related
related to DRIVERS-2226 Fix server version incompatibility fo... Implementing
Driver Changes: Needed
Downstream Changes Summary:

The minServerVersion was updated for some test cases in the updateOne-let and updateMany-let CRUD spec tests. Drivers should sync CRUD spec tests to mongodb/specifications@4a8ac5f.

Driver Compliance:
Key Status/Resolution FixVersion
CXX-2455 Fixed 3.7.0
CSHARP-4059 Duplicate
GODRIVER-2313 Fixed 1.9.0
JAVA-4497 Duplicate
NODE-4013 Fixed 4.4.1
MOTOR-898 Duplicate
PYTHON-3129 Done
RUBY-2910 Fixed 2.18.0
RUST-1188 Duplicate
SWIFT-1497 Won't Do
PHPLIB-748 Fixed 1.13.0-beta1, 1.13.0
CDRIVER-4198 Fixed 1.22.0, 1.22.0-beta0

 Description   

bailey.pearson observed that the updateOne-let.yml and updateMany-let.yml tests introduced in mongodb/specifications@1519da9 for DRIVERS-1788 use pipeline-style updates (4.2+) despite the tests specifying a minServerVersion of 3.6.0.

These tests should either have minServerVersion bumped to 4.2.0 or be changed to not use pipeline-style updates.

Per the docs examples in Use Variables in let Option or c Field, it looks like we can reference bound variables in the update's query by using $expr to access the aggregation context. This should be portable for pre-4.2 servers if we'd rather not bump the minServerVersion.

AFAIK, $expr cannot be used in a non-pipeline update, so we'd need to require 4.2+ if we still want to access the bond variables from the update itself (i.e. u parameter).



 Comments   
Comment by Dmitry Rybakov [ 17/Feb/22 ]

jmikola replaceOne-let.yml should be fine. It does not use pipeline for update, only for filter. So, a proper error is raised by the server here.

I tested against 3.6.23:

db.runCommand({update: "coll0",  updates: [{q: {$expr: {$eq: ["$_id", "$$id"]}}, u: {x: "bar"} } ], let: {id: 2}})
MongoServerError: BSON field 'update.let' is an unknown field.

We can raise minServerVersion to be 100% safe, but the existing test should work properly.

Comment by Jeremy Mikola [ 16/Feb/22 ]

dmitry.rybakov: Are we sure that replaceOne-let.yml didn't also need to be changed? I see it uses errorContains for the server-side error assertion, so perhaps not.

Just thought of this while reviewing mongodb/specifications#1132 for DRIVERS-2183.

Comment by Githook User [ 16/Feb/22 ]

Author:

{'name': 'Dmitry Rybakov', 'email': 'dmitry.rybakov@mongodb.com', 'username': 'comandeo'}

Message: DRIVERS-2210 Fix server versions for update*-let (#1150)
Branch: master
https://github.com/mongodb/specifications/commit/4a8ac5fff26001a23fdd49f51f582459daf04e7d

Comment by Jeremy Mikola [ 16/Feb/22 ]

https://github.com/mongodb/specifications/pull/1150

Comment by Dmitry Rybakov [ 16/Feb/22 ]

The buggy test still may pass on some driver because the error thrown by server depends on order of field in update command:

 

db.runCommand({update: "coll0", let: {x: "foo"}, updates: [{q: {_id: 1}, u: [{$set: {x: "$$x"}}]}]})
MongoServerError: BSON field 'update.let' is an unknown field.
//
// HOWEVER
//
db.runCommand({update: "coll0",  updates: [{q: {_id: 1}, u: [{$set: {x: "$$x"}}]}], let: {x: "foo"}})
MongoServerError: BSON field 'update.updates.u' is the wrong type 'array', expected type 'object'

 

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