emqx / mongodb-erlang

MongoDB driver for Erlang
Apache License 2.0
9 stars 14 forks source link

How to create tables and indixes? #45

Open Vkutovoy92 opened 3 months ago

Vkutovoy92 commented 3 months ago

I see no instructions how to create new tables and it is not very clear how to create indixes, as example

mongo_api:command(afsts_mongo_master, #{<<"createIndexes">> => <<"merchants">>, <<"indexes">> => [#{<<"key">> => #{<<"public_key">> => 1}, <<"name">> => <<"id_public_key">>}]}, 1000)

Doesn't work

When I use old api with application:set_env(mongodb, use_legacy_protocol, true), And ok = mongo_api:ensure_index(?MASTER, CollectionName, Index)

it gives OK but doesn't create indexes and tables if it is not exist

Vkutovoy92 commented 3 months ago

I have figured out, it looks as mongo_api:command(afsts_mongo_master, {<<"createIndexes">>, <<"merchants">>, <<"indexes">>, [#{<<"key">> => #{<<"test_index_1">> => 1}, <<"name">> => <<"test_index_1">>}]}, 5000)