Skip to content

Commit

Permalink
GODRIVER-3475 Correct CreateCollection docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdale committed Feb 7, 2025
1 parent a3ad820 commit e05f1d1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions mongo/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ func (db *Database) Name() string {
return db.name
}

// Collection gets a handle for a collection with the given name configured with the given CollectionOptions.
// Collection returns a handle for a collection with the given name and options.
//
// If the collection does not exist on the server, it will be created when a
// write operation is performed.
func (db *Database) Collection(name string, opts ...options.Lister[options.CollectionOptions]) *Collection {
return newCollection(db, name, opts...)
}
Expand Down Expand Up @@ -582,14 +585,15 @@ func (db *Database) Watch(ctx context.Context, pipeline interface{},
return newChangeStream(ctx, csConfig, pipeline, opts...)
}

// CreateCollection executes a create command to explicitly create a new collection with the specified name on the
// server. If the collection being created already exists, this method will return a mongo.CommandError. This method
// requires driver version 1.4.0 or higher.
// CreateCollection immediately creates a new collection on the server with the
// specified name and options.
//
// The opts parameter can be used to specify options for the operation (see the options.CreateCollectionOptions
// documentation).
// MongoDB versions < 7.0 will return an error if the collection already exists.
// MongoDB versions >= 7.0 will not return an error if an existing collection
// created with the same name and options already exists.
//
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/create/.
// For more information about the command, see
// https://www.mongodb.com/docs/manual/reference/command/create/.
func (db *Database) CreateCollection(ctx context.Context, name string, opts ...options.Lister[options.CreateCollectionOptions]) error {
args, err := mongoutil.NewOptions(opts...)
if err != nil {
Expand Down

0 comments on commit e05f1d1

Please sign in to comment.