emqx / mongodb-erlang

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

feat: add mongo_api:ping/2 #34

Closed terry-xiaoyu closed 1 year ago

terry-xiaoyu commented 1 year ago

Add mongo_api:ping/2 for health check purposes. It will be called by the emqx_backend_mongo_actions:on_get_resource_status to test if the connection between emqx and mongodb works well.

Before this change, we have to use mongo_api:find_one(Conn, <<"foo">>, {}, #{}, 0, infinity) to test the connectivity, where <<"foo">> is a dummy collection may or may not be present in the mongodb.

kjellwinblad commented 1 year ago

@terry-xiaoyu can you explain what the purpose of the ping command is. Could the user not get the same functionality from calling the command functions?

terry-xiaoyu commented 1 year ago

@terry-xiaoyu can you explain what the purpose of the ping command is. Could the user not get the same functionality from calling the command functions?

Will be called by emqx_backend_mongo_actions:on_get_resource_status, I added some descriptions to this PR just now.

According to the existing design, the user can only call the APIs exported by mongo_api, so to follow its style, I added a new API ping to mongo_api, and also a ping_query function to pack the ping record.

kjellwinblad commented 1 year ago

I think it is better to add a command/2 function to the mongo_api module that is similar to the command/2 function in the mc_worker_api module. Then we will have a much more general function that can be used to execute many Mongo DB commands and not only ping.

@terry-xiaoyu what do you think?

terry-xiaoyu commented 1 year ago

I think it is better to add a command/2 function to the mongo_api module that is similar to the command/2 function in the mc_worker_api module. Then we will have a much more general function that can be used to execute many Mongo DB commands and not only ping.

@terry-xiaoyu what do you think?

OK, I will add a command API too.

terry-xiaoyu commented 1 year ago

Updated:

Added the mongo_api:command/3, and removed the ping API.