Skip to content

Commit ceaedd5

Browse files
author
Divjot Arora
authored
GODRIVER-1622 Error for allowDiskUse find option on older servers (#412)
1 parent 6101f15 commit ceaedd5

File tree

7 files changed

+183
-7
lines changed

7 files changed

+183
-7
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"runOn": [
3+
{
4+
"maxServerVersion": "3.0.99"
5+
}
6+
],
7+
"collection_name": "test_find_allowdiskuse_clienterror",
8+
"tests": [
9+
{
10+
"description": "Find fails when allowDiskUse true is specified against pre 3.2 server",
11+
"operations": [
12+
{
13+
"object": "collection",
14+
"name": "find",
15+
"arguments": {
16+
"filter": {},
17+
"allowDiskUse": true
18+
},
19+
"error": true
20+
}
21+
],
22+
"expectations": []
23+
},
24+
{
25+
"description": "Find fails when allowDiskUse false is specified against pre 3.2 server",
26+
"operations": [
27+
{
28+
"object": "collection",
29+
"name": "find",
30+
"arguments": {
31+
"filter": {},
32+
"allowDiskUse": false
33+
},
34+
"error": true
35+
}
36+
],
37+
"expectations": []
38+
}
39+
]
40+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
runOn:
2+
- { maxServerVersion: "3.0.99" }
3+
4+
collection_name: &collection_name 'test_find_allowdiskuse_clienterror'
5+
6+
tests:
7+
-
8+
description: "Find fails when allowDiskUse true is specified against pre 3.2 server"
9+
operations:
10+
-
11+
object: collection
12+
name: find
13+
arguments:
14+
filter: { }
15+
allowDiskUse: true
16+
error: true
17+
expectations: []
18+
-
19+
description: "Find fails when allowDiskUse false is specified against pre 3.2 server"
20+
operations:
21+
-
22+
object: collection
23+
name: find
24+
arguments:
25+
filter: { }
26+
allowDiskUse: false
27+
error: true
28+
expectations: []
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "3.2",
5+
"maxServerVersion": "4.3.0"
6+
}
7+
],
8+
"collection_name": "test_find_allowdiskuse_servererror",
9+
"tests": [
10+
{
11+
"description": "Find fails when allowDiskUse true is specified against pre 4.4 server (server-side error)",
12+
"operations": [
13+
{
14+
"object": "collection",
15+
"name": "find",
16+
"arguments": {
17+
"filter": {},
18+
"allowDiskUse": true
19+
},
20+
"error": true
21+
}
22+
],
23+
"expectations": [
24+
{
25+
"command_started_event": {
26+
"command": {
27+
"find": "test_find_allowdiskuse_servererror",
28+
"filter": {},
29+
"allowDiskUse": true
30+
}
31+
}
32+
}
33+
]
34+
},
35+
{
36+
"description": "Find fails when allowDiskUse false is specified against pre 4.4 server (server-side error)",
37+
"operations": [
38+
{
39+
"object": "collection",
40+
"name": "find",
41+
"arguments": {
42+
"filter": {},
43+
"allowDiskUse": false
44+
},
45+
"error": true
46+
}
47+
],
48+
"expectations": [
49+
{
50+
"command_started_event": {
51+
"command": {
52+
"find": "test_find_allowdiskuse_servererror",
53+
"filter": {},
54+
"allowDiskUse": false
55+
}
56+
}
57+
}
58+
]
59+
}
60+
]
61+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
runOn:
2+
# These tests assert that the driver does not raise client-side errors and
3+
# instead relies on the server to raise an error. Server versions >= 3.2.0
4+
# raise errors for unknown find options, and server versions >= 4.3.1
5+
# support the allowDiskUse option in find.
6+
- { minServerVersion: "3.2", maxServerVersion: "4.3.0" }
7+
8+
collection_name: &collection_name 'test_find_allowdiskuse_servererror'
9+
10+
tests:
11+
-
12+
description: "Find fails when allowDiskUse true is specified against pre 4.4 server (server-side error)"
13+
operations:
14+
-
15+
object: collection
16+
name: find
17+
arguments:
18+
filter: &filter { }
19+
allowDiskUse: true
20+
error: true
21+
expectations:
22+
-
23+
command_started_event:
24+
command:
25+
find: *collection_name
26+
filter: *filter
27+
allowDiskUse: true
28+
-
29+
description: "Find fails when allowDiskUse false is specified against pre 4.4 server (server-side error)"
30+
operations:
31+
-
32+
object: collection
33+
name: find
34+
arguments:
35+
filter: *filter
36+
allowDiskUse: false
37+
error: true
38+
expectations:
39+
-
40+
command_started_event:
41+
command:
42+
find: *collection_name
43+
filter: *filter
44+
allowDiskUse: false

mongo/options/findoptions.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212

1313
// FindOptions represents options that can be used to configure a Find operation.
1414
type FindOptions struct {
15-
// If true, the server can write temporary data to disk while executing the find operation. The default value
16-
// is false. This option is only valid for MongoDB versions >= 4.4. Older servers >= 3.2 will report an error for
17-
// using this option. For servers < 3.2, this setting is ignored.
15+
// If true, the server can write temporary data to disk while executing the find operation. This option is only
16+
// valid for MongoDB versions >= 4.4. Server versions >= 3.2 will report an error if this option is specified. For
17+
// server versions < 3.2, the driver will return a client-side error if this option is specified. The default value
18+
// is false.
1819
AllowDiskUse *bool
1920

2021
// If true, an operation on a sharded cluster can return partial results if some shards are down rather than

x/mongo/driver/operation/find.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/mongo/driver/operation/find.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ documentation = "AllowPartialResults when true allows partial results to be retu
9292

9393
[request.allowDiskUse]
9494
type = "boolean"
95-
documentation = "AllowDiskUse when true allows temporary data to be written to disk during the find command. Valid for server versions >= 4.4. Older servers >= 3.2 will report an error for using this option. For servers < 3.2, this setting is ignored."
95+
minWireVersionRequired = 4
96+
documentation = "AllowDiskUse when true allows temporary data to be written to disk during the find command."
9697

9798
[request.collation]
9899
type = "document"

0 commit comments

Comments
 (0)