开发者

How to use geo indexing in erlang mongodb?

Two little questions to ask:

  1. I want to do geo indexing mentioned here so I can find nearby places. It is said to be

    db.places.ensureIndex( {loc : "2d"} )

in that doc. But since erlang can't store "2d" as string, I am wandering which one of the following code is right in erlang:

mongo:开发者_Go百科create_index(foo, {loc,  <<"2d">> })
mongo:create_index(foo, {loc,  '2d' } )
mongo:create_index(foo, {loc, '$2d'} )

All get ok result. Which is the right one?

  1. There's no ensure index for erlang driver. And I don't see any API that can get index information. Then how can I just create index for once in an elegant way?

Thanks very much!


Use <<"2d">>. Mongo does not use atoms in its meta data.

You should keep your administrative/setup procedure separate from your query/update procedures. Put your index creation, capped collection creation, etc. in this setup procedure and run it when setting up a new system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜