@@ -110,7 +110,10 @@ func (db *Database) Name() string {
110110 return db .name
111111}
112112
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.
114117func (db * Database ) Collection (name string , opts ... options.Lister [options.CollectionOptions ]) * Collection {
115118 return newCollection (db , name , opts ... )
116119}
@@ -583,14 +586,15 @@ func (db *Database) Watch(ctx context.Context, pipeline interface{},
583586 return newChangeStream (ctx , csConfig , pipeline , opts ... )
584587}
585588
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.
589591//
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.
592595//
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/.
594598func (db * Database ) CreateCollection (ctx context.Context , name string , opts ... options.Lister [options.CreateCollectionOptions ]) error {
595599 args , err := mongoutil .NewOptions (opts ... )
596600 if err != nil {
@@ -873,19 +877,20 @@ func (db *Database) createCollectionOperation(
873877 return op , nil
874878}
875879
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.
879881//
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.
881887//
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.
883891//
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.
889894func (db * Database ) CreateView (ctx context.Context , viewName , viewOn string , pipeline interface {},
890895 opts ... options.Lister [options.CreateViewOptions ]) error {
891896
0 commit comments