Skip to content

Commit 458228f

Browse files
RUST-2087 Add hint option to distinct (#1341)
1 parent 7429896 commit 458228f

File tree

4 files changed

+217
-1
lines changed

4 files changed

+217
-1
lines changed

src/action/distinct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33
use bson::{Bson, Document};
44

55
use crate::{
6-
coll::options::DistinctOptions,
6+
coll::options::{DistinctOptions, Hint},
77
collation::Collation,
88
error::Result,
99
operation::Distinct as Op,

src/coll/options.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,10 @@ pub struct DistinctOptions {
764764
///
765765
/// This option is only available on server versions 4.4+.
766766
pub comment: Option<Bson>,
767+
768+
/// A document or string that specifies the index to use to support the query predicate.
769+
/// Available on server versions 7.1+.
770+
pub hint: Option<Hint>,
767771
}
768772

769773
/// Specifies the options to a [`Collection::find`](../struct.Collection.html#method.find)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"description": "distinct-hint",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "7.1.0"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0",
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "distinct-hint-tests"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "coll0"
30+
}
31+
}
32+
],
33+
"initialData": [
34+
{
35+
"collectionName": "coll0",
36+
"databaseName": "distinct-hint-tests",
37+
"documents": [
38+
{
39+
"_id": 1,
40+
"x": 11
41+
},
42+
{
43+
"_id": 2,
44+
"x": 22
45+
},
46+
{
47+
"_id": 3,
48+
"x": 33
49+
}
50+
]
51+
}
52+
],
53+
"tests": [
54+
{
55+
"description": "distinct with hint string",
56+
"operations": [
57+
{
58+
"name": "distinct",
59+
"object": "collection0",
60+
"arguments": {
61+
"fieldName": "x",
62+
"filter": {
63+
"_id": 1
64+
},
65+
"hint": "_id_"
66+
},
67+
"expectResult": [
68+
11
69+
]
70+
}
71+
],
72+
"expectEvents": [
73+
{
74+
"client": "client0",
75+
"events": [
76+
{
77+
"commandStartedEvent": {
78+
"command": {
79+
"distinct": "coll0",
80+
"key": "x",
81+
"query": {
82+
"_id": 1
83+
},
84+
"hint": "_id_"
85+
},
86+
"commandName": "distinct",
87+
"databaseName": "distinct-hint-tests"
88+
}
89+
}
90+
]
91+
}
92+
]
93+
},
94+
{
95+
"description": "distinct with hint document",
96+
"operations": [
97+
{
98+
"name": "distinct",
99+
"object": "collection0",
100+
"arguments": {
101+
"fieldName": "x",
102+
"filter": {
103+
"_id": 1
104+
},
105+
"hint": {
106+
"_id": 1
107+
}
108+
},
109+
"expectResult": [
110+
11
111+
]
112+
}
113+
],
114+
"expectEvents": [
115+
{
116+
"client": "client0",
117+
"events": [
118+
{
119+
"commandStartedEvent": {
120+
"command": {
121+
"distinct": "coll0",
122+
"key": "x",
123+
"query": {
124+
"_id": 1
125+
},
126+
"hint": {
127+
"_id": 1
128+
}
129+
},
130+
"commandName": "distinct",
131+
"databaseName": "distinct-hint-tests"
132+
}
133+
}
134+
]
135+
}
136+
]
137+
}
138+
]
139+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
description: "distinct-hint"
2+
3+
schemaVersion: "1.0"
4+
runOnRequirements:
5+
# https://jira.mongodb.org/browse/SERVER-14227
6+
# Server supports distinct with hint starting from 7.1.0.
7+
- minServerVersion: "7.1.0"
8+
9+
createEntities:
10+
- client:
11+
id: &client0 client0
12+
observeEvents: [ commandStartedEvent ]
13+
- database:
14+
id: &database0 database0
15+
client: *client0
16+
databaseName: &database0Name distinct-hint-tests
17+
- collection:
18+
id: &collection0 collection0
19+
database: *database0
20+
collectionName: &collection0Name coll0
21+
22+
initialData:
23+
- collectionName: *collection0Name
24+
databaseName: *database0Name
25+
documents:
26+
- { _id: 1, x: 11 }
27+
- { _id: 2, x: 22 }
28+
- { _id: 3, x: 33 }
29+
30+
tests:
31+
- description: "distinct with hint string"
32+
operations:
33+
- name: distinct
34+
object: *collection0
35+
arguments:
36+
fieldName: &fieldName x
37+
filter: &filter { _id: 1 }
38+
hint: _id_
39+
expectResult: [ 11 ]
40+
expectEvents:
41+
- client: *client0
42+
events:
43+
- commandStartedEvent:
44+
command:
45+
distinct: *collection0Name
46+
key: *fieldName
47+
query: *filter
48+
hint: _id_
49+
commandName: distinct
50+
databaseName: *database0Name
51+
52+
- description: "distinct with hint document"
53+
operations:
54+
- name: distinct
55+
object: *collection0
56+
arguments:
57+
fieldName: *fieldName
58+
filter: *filter
59+
hint:
60+
_id: 1
61+
expectResult: [ 11 ]
62+
expectEvents:
63+
- client: *client0
64+
events:
65+
- commandStartedEvent:
66+
command:
67+
distinct: *collection0Name
68+
key: *fieldName
69+
query: *filter
70+
hint:
71+
_id: 1
72+
commandName: distinct
73+
databaseName: *database0Name

0 commit comments

Comments
 (0)