@@ -110,7 +110,10 @@ func (db *Database) Name() string {
110
110
return db .name
111
111
}
112
112
113
- // Collection gets a handle for a collection with the given name configured with the given CollectionOptions.
113
+ // Collection returns a handle for a collection with the given name and options.
114
+ //
115
+ // If the collection does not exist on the server, it will be created when a
116
+ // write operation is performed.
114
117
func (db * Database ) Collection (name string , opts ... options.Lister [options.CollectionOptions ]) * Collection {
115
118
return newCollection (db , name , opts ... )
116
119
}
@@ -583,14 +586,15 @@ func (db *Database) Watch(ctx context.Context, pipeline interface{},
583
586
return newChangeStream (ctx , csConfig , pipeline , opts ... )
584
587
}
585
588
586
- // CreateCollection executes a create command to explicitly create a new collection with the specified name on the
587
- // server. If the collection being created already exists, this method will return a mongo.CommandError. This method
588
- // requires driver version 1.4.0 or higher.
589
+ // CreateCollection creates a new collection on the server with the specified
590
+ // name and options.
589
591
//
590
- // The opts parameter can be used to specify options for the operation (see the options.CreateCollectionOptions
591
- // documentation).
592
+ // MongoDB versions < 7.0 will return an error if the collection already exists.
593
+ // MongoDB versions >= 7.0 will not return an error if an existing collection
594
+ // created with the same name and options already exists.
592
595
//
593
- // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/create/.
596
+ // For more information about the command, see
597
+ // https://www.mongodb.com/docs/manual/reference/command/create/.
594
598
func (db * Database ) CreateCollection (ctx context.Context , name string , opts ... options.Lister [options.CreateCollectionOptions ]) error {
595
599
args , err := mongoutil .NewOptions (opts ... )
596
600
if err != nil {
@@ -873,19 +877,20 @@ func (db *Database) createCollectionOperation(
873
877
return op , nil
874
878
}
875
879
876
- // CreateView executes a create command to explicitly create a view on the server. See
877
- // https://www.mongodb.com/docs/manual/core/views/ for more information about views. This method requires driver version >=
878
- // 1.4.0 and MongoDB version >= 3.4.
880
+ // CreateView creates a view on the server.
879
881
//
880
- // The viewName parameter specifies the name of the view to create.
882
+ // The viewName parameter specifies the name of the view to create. The viewOn
883
+ // parameter specifies the name of the collection or view on which this view
884
+ // will be created. The pipeline parameter specifies an aggregation pipeline
885
+ // that will be exececuted against the source collection or view to create this
886
+ // view.
881
887
//
882
- // # The viewOn parameter specifies the name of the collection or view on which this view will be created
888
+ // MongoDB versions < 7.0 will return an error if the view already exists.
889
+ // MongoDB versions >= 7.0 will not return an error if an existing view created
890
+ // with the same name and options already exists.
883
891
//
884
- // The pipeline parameter specifies an aggregation pipeline that will be exececuted against the source collection or
885
- // view to create this view.
886
- //
887
- // The opts parameter can be used to specify options for the operation (see the options.CreateViewOptions
888
- // documentation).
892
+ // See https://www.mongodb.com/docs/manual/core/views/ for more information
893
+ // about views.
889
894
func (db * Database ) CreateView (ctx context.Context , viewName , viewOn string , pipeline interface {},
890
895
opts ... options.Lister [options.CreateViewOptions ]) error {
891
896
0 commit comments