Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-3475 Correct CreateCollection and CreateView docs. #1933

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -583,14 +586,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 @@ -873,19 +877,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
Loading