1
1
use std:: time:: Duration ;
2
2
3
+ use bson:: serde_helpers;
3
4
use serde:: { de:: Error , Deserialize , Deserializer , Serialize , Serializer } ;
4
5
use serde_with:: skip_serializing_none;
5
6
use typed_builder:: TypedBuilder ;
@@ -831,6 +832,36 @@ pub struct FindOneOptions {
831
832
pub sort : Option < Document > ,
832
833
}
833
834
835
+ /// Specifies the options to a
836
+ /// [`Collection::create_index`](../struct.Collection.html#method.create_index) or [`Collection::
837
+ /// create_indexes`](../struct.Collection.html#method.create_indexes) operation.
838
+ ///
839
+ /// For more information, see [`createIndexes`](https://docs.mongodb.com/manual/reference/command/createIndexes/).
840
+ #[ serde_with:: skip_serializing_none]
841
+ #[ derive( Clone , Debug , Default , TypedBuilder , Serialize ) ]
842
+ #[ builder( field_defaults( default , setter( into) ) ) ]
843
+ #[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
844
+ #[ non_exhaustive]
845
+ pub struct CreateIndexOptions {
846
+ /// Specify the commit quorum needed to mark an `index` as ready.
847
+ pub commit_quorum : Option < CommitQuorum > ,
848
+
849
+ /// The maximum amount of time to allow the index to build.
850
+ ///
851
+ /// This option maps to the `maxTimeMS` MongoDB query option, so the duration will be sent
852
+ /// across the wire as an integer number of milliseconds.
853
+ #[ serde(
854
+ rename = "maxTimeMS" ,
855
+ default ,
856
+ serialize_with = "bson_util::serialize_duration_option_as_int_millis" ,
857
+ deserialize_with = "bson_util::deserialize_duration_option_from_u64_millis"
858
+ ) ]
859
+ pub max_time : Option < Duration > ,
860
+
861
+ /// The write concern for the operation.
862
+ pub write_concern : Option < WriteConcern > ,
863
+ }
864
+
834
865
/// Specifies the options to a [`Collection::drop`](../struct.Collection.html#method.drop)
835
866
/// operation.
836
867
#[ serde_with:: skip_serializing_none]
@@ -842,3 +873,114 @@ pub struct DropCollectionOptions {
842
873
/// The write concern for the operation.
843
874
pub write_concern : Option < WriteConcern > ,
844
875
}
876
+
877
+ /// Specifies the options to a
878
+ /// [`Collection::drop_index`](../struct.Collection.html#method.drop_index) or
879
+ /// [`Collection::drop_indexes`](../struct.Collection.html#method.drop_indexes) operation.
880
+ #[ serde_with:: skip_serializing_none]
881
+ #[ derive( Clone , Debug , Default , Deserialize , TypedBuilder , Serialize ) ]
882
+ #[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
883
+ #[ builder( field_defaults( default , setter( into) ) ) ]
884
+ #[ non_exhaustive]
885
+ pub struct DropIndexOptions {
886
+ /// The maximum amount of time to allow the index to drop.
887
+ ///
888
+ /// This option maps to the `maxTimeMS` MongoDB query option, so the duration will be sent
889
+ /// across the wire as an integer number of milliseconds.
890
+ #[ serde(
891
+ rename = "maxTimeMS" ,
892
+ default ,
893
+ serialize_with = "bson_util::serialize_duration_option_as_int_millis" ,
894
+ deserialize_with = "bson_util::deserialize_duration_option_from_u64_millis"
895
+ ) ]
896
+ pub max_time : Option < Duration > ,
897
+
898
+ /// The write concern for the operation.
899
+ pub write_concern : Option < WriteConcern > ,
900
+ }
901
+
902
+ /// Specifies the options to a
903
+ /// [`Collection::list_indexes`](../struct.Collection.html#method.list_indexes) operation.
904
+ #[ serde_with:: skip_serializing_none]
905
+ #[ derive( Clone , Debug , Default , Deserialize , TypedBuilder , Serialize ) ]
906
+ #[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
907
+ #[ builder( field_defaults( default , setter( into) ) ) ]
908
+ #[ non_exhaustive]
909
+ pub struct ListIndexOptions {
910
+ /// The maximum amount of time to search for the index.
911
+ ///
912
+ /// This option maps to the `maxTimeMS` MongoDB query option, so the duration will be sent
913
+ /// across the wire as an integer number of milliseconds.
914
+ #[ serde(
915
+ rename = "maxTimeMS" ,
916
+ default ,
917
+ serialize_with = "bson_util::serialize_duration_option_as_int_millis" ,
918
+ deserialize_with = "bson_util::deserialize_duration_option_from_u64_millis"
919
+ ) ]
920
+ pub max_time : Option < Duration > ,
921
+
922
+ /// The number of indexes the server should return per cursor batch.
923
+ #[ serde( default , serialize_with = "bson_util::serialize_u32_option_as_i32" ) ]
924
+ pub batch_size : Option < u32 > ,
925
+ }
926
+
927
+ /// The minimum number of data-bearing voting replica set members (i.e. commit quorum), including
928
+ /// the primary, that must report a successful index build before the primary marks the indexes as
929
+ /// ready.
930
+ ///
931
+ /// For more information, see the [documentation](https://docs.mongodb.com/manual/reference/command/createIndexes/#definition)
932
+ #[ derive( Clone , Debug , PartialEq ) ]
933
+ #[ non_exhaustive]
934
+ pub enum CommitQuorum {
935
+ /// A specific number of voting replica set members. When set to 0, disables quorum voting.
936
+ Nodes ( u32 ) ,
937
+
938
+ /// All data-bearing voting replica set members (default).
939
+ VotingMembers ,
940
+
941
+ /// A simple majority of voting members.
942
+ Majority ,
943
+
944
+ /// A replica set tag name.
945
+ Custom ( String ) ,
946
+ }
947
+
948
+ impl Serialize for CommitQuorum {
949
+ fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
950
+ where
951
+ S : Serializer ,
952
+ {
953
+ match self {
954
+ CommitQuorum :: Nodes ( n) => serde_helpers:: serialize_u32_as_i32 ( n, serializer) ,
955
+ CommitQuorum :: VotingMembers => serializer. serialize_str ( "votingMembers" ) ,
956
+ CommitQuorum :: Majority => serializer. serialize_str ( "majority" ) ,
957
+ CommitQuorum :: Custom ( s) => serializer. serialize_str ( s) ,
958
+ }
959
+ }
960
+ }
961
+
962
+ impl < ' de > Deserialize < ' de > for CommitQuorum {
963
+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
964
+ where
965
+ D : Deserializer < ' de > ,
966
+ {
967
+ #[ derive( Deserialize ) ]
968
+ #[ serde( untagged) ]
969
+ enum IntOrString {
970
+ Int ( u32 ) ,
971
+ String ( String ) ,
972
+ }
973
+ match IntOrString :: deserialize ( deserializer) ? {
974
+ IntOrString :: String ( s) => {
975
+ if s == "votingMembers" {
976
+ Ok ( CommitQuorum :: VotingMembers )
977
+ } else if s == "majority" {
978
+ Ok ( CommitQuorum :: Majority )
979
+ } else {
980
+ Ok ( CommitQuorum :: Custom ( s) )
981
+ }
982
+ }
983
+ IntOrString :: Int ( i) => Ok ( CommitQuorum :: Nodes ( i) ) ,
984
+ }
985
+ }
986
+ }
0 commit comments