How to index a field with mongodb-erlang

151 views Asked by At

I want to index a field using mongodb-erlang (https://github.com/comtihon/mongodb-erlang). The sample code works in shell but crashed when i called from code. Anyone have an idea about this issue? I'm using mongo 2.6.5

mongo:ensure_index(DBConn, conversations, {key, {page_id, 1}, unique, true, dropDups, true})

Thanks

1

There are 1 answers

7
Chen Yu On BEST ANSWER

I have used mongodb-erlang for more than one year, and the sample code is as follows:

Index_spec = [{key,{column_a,1},unique,true,sparse,true}
                          ],
X = collection_a,
 ok = mongo:ensure_index(Connection,X,Index_spec),