Skip to content

getCollection does not return nil on non existing collection #23

@xavierpantet

Description

@xavierpantet

Hi,
I am not sure whether this is an intended behaviour or not but I think the way getCollection() on MongoDatabase works is a bit strange.

The method's signature is the following:

func getCollection(name collectionName: String) -> MongoCollection?

Therefore, I expect to get a valid collection when collectionName corresponds to an existing collection in my database and nil when collectionName does not exist.

Instead of this, I indeed get the correct collection when collectionName is valid but when it's not I'm getting new empty collection that apparently does not even belong to my database.

Am I missing something from the doc or is there really a problem here?
Thank you in advance 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions