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 d3e6168
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 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 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 Expand Up @@ -872,19 +876,20 @@ func (db *Database) createCollectionOperation(
return op, nil
}

// CreateView executes a create command to explicitly create a view on the server. See
// https://www.mongodb.com/docs/manual/core/views/ for more information about views. This method requires driver version >=
// 1.4.0 and MongoDB version >= 3.4.
// CreateView creates a view on the server.
//
// The viewName parameter specifies the name of the view to create.
// The viewName parameter specifies the name of the view to create. The viewOn
// parameter specifies the name of the collection or view on which this view
// will be created. The pipeline parameter specifies an aggregation pipeline
// that will be exececuted against the source collection or view to create this
// view.
//
// # The viewOn parameter specifies the name of the collection or view on which this view will be created
// MongoDB versions < 7.0 will return an error if the view already exists.
// MongoDB versions >= 7.0 will not return an error if an existing view created
// with the same name and options already exists.
//
// The pipeline parameter specifies an aggregation pipeline that will be exececuted against the source collection or
// view to create this view.
//
// The opts parameter can be used to specify options for the operation (see the options.CreateViewOptions
// documentation).
// See https://www.mongodb.com/docs/manual/core/views/ for more information
// about views.
func (db *Database) CreateView(ctx context.Context, viewName, viewOn string, pipeline interface{},
opts ...options.Lister[options.CreateViewOptions]) error {

Expand Down

0 comments on commit d3e6168

Please sign in to comment.