Skip to content

Commit d3e6168

Browse files
committed
GODRIVER-3475 Correct CreateCollection docs.
1 parent a3ad820 commit d3e6168

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

mongo/database.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
114117
func (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 creates a new collection on the server with the specified
589+
// 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/.
593597
func (db *Database) CreateCollection(ctx context.Context, name string, opts ...options.Lister[options.CreateCollectionOptions]) error {
594598
args, err := mongoutil.NewOptions(opts...)
595599
if err != nil {
@@ -872,19 +876,20 @@ func (db *Database) createCollectionOperation(
872876
return op, nil
873877
}
874878

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

0 commit comments

Comments
 (0)