mongodb/action/
create_collection.rs1use crate::bson::{Bson, Document};
2use std::time::Duration;
3
4use crate::{
5 collation::Collation,
6 concern::WriteConcern,
7 db::options::{
8 ChangeStreamPreAndPostImages,
9 ClusteredIndex,
10 IndexOptionDefaults,
11 TimeseriesOptions,
12 ValidationAction,
13 ValidationLevel,
14 },
15 options::CreateCollectionOptions,
16 ClientSession,
17 Database,
18};
19
20use super::{deeplink, export_doc, option_setters, options_doc};
21
22impl Database {
23 #[deeplink]
30 #[options_doc(create_coll)]
31 pub fn create_collection(&self, name: impl Into<String>) -> CreateCollection {
32 CreateCollection {
33 db: self,
34 name: name.into(),
35 options: None,
36 session: None,
37 }
38 }
39}
40
41#[cfg(feature = "sync")]
42impl crate::sync::Database {
43 #[deeplink]
50 #[options_doc(create_coll, sync)]
51 pub fn create_collection(&self, name: impl Into<String>) -> CreateCollection {
52 self.async_database.create_collection(name)
53 }
54}
55
56#[must_use]
58pub struct CreateCollection<'a> {
59 pub(crate) db: &'a Database,
60 pub(crate) name: String,
61 pub(crate) options: Option<CreateCollectionOptions>,
62 pub(crate) session: Option<&'a mut ClientSession>,
63}
64
65#[option_setters(crate::db::options::CreateCollectionOptions)]
66#[export_doc(create_coll)]
67impl<'a> CreateCollection<'a> {
68 pub fn session(mut self, value: impl Into<&'a mut ClientSession>) -> Self {
70 self.session = Some(value.into());
71 self
72 }
73}
74
75