@@ -4,6 +4,7 @@ use crate::{
4
4
bson:: { doc, Bson } ,
5
5
bson_util,
6
6
cmap:: { CommandResponse , StreamDescription } ,
7
+ coll:: options:: Hint ,
7
8
concern:: { Acknowledgment , WriteConcern } ,
8
9
error:: { ErrorKind , WriteConcernError , WriteError , WriteFailure } ,
9
10
operation:: { Operation , Update } ,
@@ -62,6 +63,62 @@ async fn build() {
62
63
assert_eq ! ( cmd. body, expected_body) ;
63
64
}
64
65
66
+ #[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
67
+ #[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
68
+ async fn build_hint ( ) {
69
+ let ns = Namespace {
70
+ db : "test_db" . to_string ( ) ,
71
+ coll : "test_coll" . to_string ( ) ,
72
+ } ;
73
+ let filter = doc ! { "x" : { "$gt" : 1 } } ;
74
+ let update = UpdateModifications :: Document ( doc ! { "x" : { "$inc" : 1 } } ) ;
75
+ let wc = WriteConcern {
76
+ w : Some ( Acknowledgment :: Majority ) ,
77
+ ..Default :: default ( )
78
+ } ;
79
+ let options = UpdateOptions {
80
+ upsert : Some ( false ) ,
81
+ bypass_document_validation : Some ( true ) ,
82
+ write_concern : Some ( wc) ,
83
+ hint : Some ( Hint :: Keys ( doc ! { "x" : 1 , "y" : -1 } ) ) ,
84
+ ..Default :: default ( )
85
+ } ;
86
+
87
+ let op = Update :: new ( ns, filter. clone ( ) , update. clone ( ) , false , Some ( options) ) ;
88
+
89
+ let description = StreamDescription :: new_testing ( ) ;
90
+ let mut cmd = op. build ( & description) . unwrap ( ) ;
91
+
92
+ assert_eq ! ( cmd. name. as_str( ) , "update" ) ;
93
+ assert_eq ! ( cmd. target_db. as_str( ) , "test_db" ) ;
94
+ assert_eq ! ( cmd. read_pref. as_ref( ) , None ) ;
95
+
96
+ let mut expected_body = doc ! {
97
+ "update" : "test_coll" ,
98
+ "updates" : [
99
+ {
100
+ "q" : filter,
101
+ "u" : update. to_bson( ) ,
102
+ "upsert" : false ,
103
+ "hint" : {
104
+ "x" : 1 ,
105
+ "y" : -1 ,
106
+ } ,
107
+ }
108
+ ] ,
109
+ "writeConcern" : {
110
+ "w" : "majority"
111
+ } ,
112
+ "bypassDocumentValidation" : true ,
113
+ "ordered" : true ,
114
+ } ;
115
+
116
+ bson_util:: sort_document ( & mut cmd. body ) ;
117
+ bson_util:: sort_document ( & mut expected_body) ;
118
+
119
+ assert_eq ! ( cmd. body, expected_body) ;
120
+ }
121
+
65
122
#[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
66
123
#[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
67
124
async fn build_many ( ) {
0 commit comments