Skip to content

Commit 0c9b061

Browse files
committed
GODRIVER-301: add name method to collection type
Change-Id: Ia5df38436b43eecf000fcf57e6cff19e9ee77a4f
1 parent c6cbbd6 commit 0c9b061

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mongo/collection.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func newCollection(db *Database, name string) *Collection {
4848
return coll
4949
}
5050

51+
// Name provides access to the name of the collection.
52+
func (coll *Collection) Name() string {
53+
return coll.name
54+
}
55+
5156
// namespace returns the namespace of the collection.
5257
func (coll *Collection) namespace() command.Namespace {
5358
return command.NewNamespace(coll.db.name, coll.name)

mongo/collection_internal_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ func TestCollection_namespace(t *testing.T) {
7676
require.Equal(t, namespace.FullName(), fmt.Sprintf("%s.%s", dbName, collName))
7777
}
7878

79+
func TestCollection_name_accessor(t *testing.T) {
80+
t.Parallel()
81+
82+
dbName := "foo"
83+
collName := "bar"
84+
85+
coll := createTestCollection(t, &dbName, &collName)
86+
namespace := coll.namespace()
87+
require.Equal(t, coll.Name(), collName)
88+
require.Equal(t, coll.Name(), namespace.Collection)
89+
90+
}
91+
7992
func TestCollection_InsertOne(t *testing.T) {
8093
if testing.Short() {
8194
t.Skip("skipping integration test in short mode")

0 commit comments

Comments
 (0)