MongoDB golang driver CreateCollection doesn't create a collection

185 Views Asked by At

Whenever I try the simple method Createcollection like this: client.Database("TestCluster").CreateCollection(context.TODO(), "users", options.CreateCollection().SetMaxDocuments(100000))

And I access mongoDB Atlas (free tier) seems like it doesn't have any collection created. My assumption is that I cannot create a collection unless I put some data in it. (I cannot create an empty collection).

Can somebody shine me some light? Thanks :)

Docs: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo/options#CreateCollectionOptions.SetMaxDocuments https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Database.CreateCollection

1

There are 1 best solutions below

0
On

Dumb me...! Whenever SetMaxDocuments() is called you also need to set SetCapped(true) So yes, it's possible to have an empty collection :)