Create a collection from inside an atlas function?

I have an Atlas function where I try to create a collection:

exports = async function(arg){
var atlas =“mongodb-atlas”)
var db = atlas.db(“one”);
But I get
error: {“message”:“‘createCollection’ is not a function”,“name”:“TypeError”}

Could it be that the database object does not allow creating collections when I’m in an Atlas function? Its stringification looks like {“collection”:{},“aggregate”:{},“getCollectionNames”:{}} . Are these three things all I can do from within an atlas function?

Hello @Robert_Nitsche, Welcome,

I found no createCollection() method in object.

I am not sure why you need to use createCollection() method, because when you insert a document it will create automatically.

You can refer to the documentation for further supported methods:

1 Like

Hello Turi Vishal, thanks for the clarification. The thing is that I want to create indexes, too, when I create collections. Is there a way to do that when a collection is created automatically by inserting a document?

Hello @Robert_Nitsche,

I think you are hitting the limitation of atlas functions, but I am not sure if might be there some alternatives, wait, someone, a MongoDB expert will give insights into your problem.

If you still are not getting any updates then ask a new question.