@@ -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}
@@ -582,14 +585,15 @@ func (db *Database) Watch(ctx context.Context, pipeline interface{},
582585 return newChangeStream (ctx , csConfig , pipeline , opts ... )
583586}
584587
585- // CreateCollection executes a create command to explicitly create a new collection with the specified name on the
586- // server. If the collection being created already exists, this method will return a mongo.CommandError. This method
587- // requires driver version 1.4.0 or higher.
588+ // CreateCollection immediately creates a new collection on the server with the
589+ // specified name and options.
588590//
589- // The opts parameter can be used to specify options for the operation (see the options.CreateCollectionOptions
590- // documentation).
591+ // MongoDB versions < 7.0 will return an error if the collection already exists.
592+ // MongoDB versions >= 7.0 will not return an error if an existing collection
593+ // created with the same name and options already exists.
591594//
592- // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/create/.
595+ // For more information about the command, see
596+ // https://www.mongodb.com/docs/manual/reference/command/create/.
593597func (db * Database ) CreateCollection (ctx context.Context , name string , opts ... options.Lister [options.CreateCollectionOptions ]) error {
594598 args , err := mongoutil .NewOptions (opts ... )
595599 if err != nil {
0 commit comments