comtihon / mongodb-erlang

MongoDB driver for Erlang
Apache License 2.0
342 stars 268 forks source link

How can I create/drop a collection using the driver #255

Open stretyak opened 1 year ago

stretyak commented 1 year ago

I have failed to find a sample could you please add a sample into readme

stretyak commented 1 year ago

Found a way

to create

mongoc:transaction(MongoConnection,
    fun(#{pool := Worker}) ->
        Cmd = {<<"create">>, mc_utils:value_to_binary(CollectionName)},
        mc_worker_api:command(Worker,Cmd)
    end, #{}),

to drop

mongoc:transaction(MongoConnection,
    fun(#{pool := Worker}) ->
        Cmd = {<<"create">>, mc_utils:value_to_binary(CollectionName)},
        mc_worker_api:command(Worker,Cmd)
    end, #{}),