ndb_mongodb_admin.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. This module provides a non-db connector to interact with MongoDB NoSQL
  15. server from configuration file. You can read more about MongoDB at
  16. <ulink url="http://www.mongodb.org">http://www.mongodb.org</ulink>.
  17. </para>
  18. <para>
  19. It can connect to many MongoDB servers and store the results in different
  20. containers.
  21. </para>
  22. </section>
  23. <section>
  24. <title>Dependencies</title>
  25. <section>
  26. <title>&kamailio; Modules</title>
  27. <para>
  28. The following modules must be loaded before this module:
  29. <itemizedlist>
  30. <listitem>
  31. <para>
  32. <emphasis>none</emphasis>.
  33. </para>
  34. </listitem>
  35. </itemizedlist>
  36. </para>
  37. </section>
  38. <section>
  39. <title>External Libraries or Applications</title>
  40. <para>
  41. The following libraries or applications must be installed before running
  42. &kamailio; with this module loaded:
  43. <itemizedlist>
  44. <listitem>
  45. <para>
  46. <emphasis>mongo-c-driver</emphasis> - available at
  47. <ulink url="https://github.com/mongodb/mongo-c-driver">https://github.com/mongodb/mongo-c-driver</ulink>
  48. </para>
  49. </listitem>
  50. </itemizedlist>
  51. </para>
  52. </section>
  53. </section>
  54. <section>
  55. <title>Parameters</title>
  56. <section id="ndb_mongodb.p.server">
  57. <title><varname>server</varname> (str)</title>
  58. <para>
  59. Specify the details to connect to REDIS server. It takes a list of
  60. attribute=value separated by semicolon, the attributes can be
  61. name and uri. Name is a generic identifier to be used
  62. with module functions. The uri parameter must be a valid
  63. MongoDB database connection string.
  64. </para>
  65. <para>
  66. You can set this parameter many times, in case you want to connect to
  67. many MongoDB servers, just give different attributes and use the specific
  68. server name when querying the MongoDB instance.
  69. </para>
  70. <para>
  71. <emphasis>
  72. Default value is NULL.
  73. </emphasis>
  74. </para>
  75. <example>
  76. <title>Set <varname>server</varname> parameter</title>
  77. <programlisting format="linespecific">
  78. ...
  79. modparam("ndb_mongodb", "server", "name=mgs1;uri='mongodb://localhost/kamailio'")
  80. modparam("ndb_mongodb", "server", "name=mgs2;uri='mongodb://127.0.0.2/kamailio'")
  81. ...
  82. </programlisting>
  83. </example>
  84. </section>
  85. </section>
  86. <section>
  87. <title>Functions</title>
  88. <section id="ndb_mongodb.f.mongodb_cmd">
  89. <title>
  90. <function moreinfo="none">mongodb_cmd(srvname, dbname, cname, command, replyid)</function>
  91. </title>
  92. <para>
  93. Send a valid command to MongoDB server identified by srvname. The reply will
  94. be stored in a local container identified by replyid. All the
  95. parameters can be strings with pseudo-variables that are evaluated
  96. at runtime.
  97. </para>
  98. <para>
  99. The reply can be accessed via pseudo-variable $mongodb(key). The key
  100. can be: type - type of the reply; value - the value in JSON format
  101. returned by MongoDB server; info - in case of error from MongoDB, it will
  102. contain an info message.
  103. </para>
  104. <para>
  105. The result can contain many documents, see mongodb_next() function for
  106. more details.
  107. </para>
  108. <para>
  109. Meaning of the parameters:
  110. <itemizedlist>
  111. <listitem>
  112. <para>
  113. <emphasis>srvname</emphasis> - MongoDB server name as given via
  114. 'server' parameter.
  115. </para>
  116. </listitem>
  117. <listitem>
  118. <para>
  119. <emphasis>dbname</emphasis> - MongoDB database name.
  120. </para>
  121. </listitem>
  122. <listitem>
  123. <para>
  124. <emphasis>cname</emphasis> - MongodDB collection (table) name.
  125. </para>
  126. </listitem>
  127. <listitem>
  128. <para>
  129. <emphasis>command</emphasis> - valid MongoDB command given
  130. as JSON string.
  131. </para>
  132. </listitem>
  133. <listitem>
  134. <para>
  135. <emphasis>replyid</emphasis> - the name of the container to
  136. store the response.
  137. </para>
  138. </listitem>
  139. </itemizedlist>
  140. </para>
  141. <para>
  142. The function can be used from ANY_ROUTE.
  143. </para>
  144. <example>
  145. <title><function>mongodb_cmd</function> usage</title>
  146. <programlisting format="linespecific">
  147. ...
  148. if(mongodb_cmd("mgs1", "kamailio", "acc", "{ \"collStats\": \"acc\" }", "mgr1")) {
  149. xlog("response from mongodb is [[$mongodb(mgr1=>value)]]\n");
  150. }
  151. ...
  152. </programlisting>
  153. </example>
  154. </section>
  155. <section id="ndb_mongodb.f.mongodb_cmd_simple">
  156. <title>
  157. <function moreinfo="none">mongodb_cmd(srvname, dbname, cname, command, replyid)</function>
  158. </title>
  159. <para>
  160. Send a valid command to MongoDB server identified by srvname. The reply will
  161. be stored in a local container identified by replyid. All the
  162. parameters can be strings with pseudo-variables that are evaluated
  163. at runtime.
  164. </para>
  165. <para>
  166. The reply can be accessed via pseudo-variable $mongodb(key). The key
  167. can be: type - type of the reply; value - the value in JSON format
  168. returned by MongoDB server; info - in case of error from MongoDB, it will
  169. contain an info message.
  170. </para>
  171. <para>
  172. This function should be used when the response has only one document.
  173. </para>
  174. <para>
  175. See mongodb_cmd() for the meaning of the parameters.
  176. </para>
  177. <para>
  178. The function can be used from ANY_ROUTE.
  179. </para>
  180. <example>
  181. <title><function>mongodb_cmd_simple</function> usage</title>
  182. <programlisting format="linespecific">
  183. ...
  184. if(mongodb_cmd_simple("mgs1", "kamailio", "acc", "{ \"collStats\": \"acc\" }", "mgr1")) {
  185. xlog("response from mongodb is [[$mongodb(mgr1=>value)]]\n");
  186. }
  187. ...
  188. </programlisting>
  189. </example>
  190. </section>
  191. <section id="ndb_mongodb.f.mongodb_find">
  192. <title>
  193. <function moreinfo="none">mongodb_find(srvname, dbname, cname, command, replyid)</function>
  194. </title>
  195. <para>
  196. Send a find command to MongoDB server identified by srvname. The reply will
  197. be stored in a local container identified by replyid. All the
  198. parameters can be strings with pseudo-variables that are evaluated
  199. at runtime.
  200. </para>
  201. <para>
  202. The reply can be accessed via pseudo-variable $mongodb(key). The key
  203. can be: type - type of the reply; value - the value in JSON format
  204. returned by MongoDB server; info - in case of error from MongoDB, it will
  205. contain an info message.
  206. </para>
  207. <para>
  208. This function is useful for querying collections and accessing the results.
  209. </para>
  210. <para>
  211. See mongodb_cmd() for the meaning of the parameters, with the remark that
  212. command has to be a valid filter JSON document, like for find() command
  213. in mongoc command line client tool.
  214. </para>
  215. <para>
  216. The function can be used from ANY_ROUTE.
  217. </para>
  218. <example>
  219. <title><function>mongodb_find</function> usage</title>
  220. <programlisting format="linespecific">
  221. ...
  222. if(mongodb_find("mgs1", "kamailio", "acc", "{ \"src_user\" : \"111\" }", "mgr1")) {
  223. xlog("response from mongodb is [[$mongodb(mgr1=>value)]]\n");
  224. }
  225. ...
  226. </programlisting>
  227. </example>
  228. </section>
  229. <section id="ndb_mongodb.f.mongodb_next">
  230. <title>
  231. <function moreinfo="none">mongodb_next(replyid)</function>
  232. </title>
  233. <para>
  234. Moves to next document in a MongoDB reply. This function can be used
  235. after a succesful mongodb_cmd() or mongodb_find(). It returns true if
  236. there is a shift to document. The current document becomes available
  237. via $mongodb(key) variable.
  238. </para>
  239. <example>
  240. <title><function>mongodb_next</function> usage</title>
  241. <programlisting format="linespecific">
  242. ...
  243. if(mongodb_find("mgs1", "kamailio", "acc", "{ \"src_user\" : \"111\" }", "mgr1")) {
  244. xlog("first response from mongodb is [[$mongodb(mgr1=>value)]]\n");
  245. while(mongodb_next("mgr1") ){
  246. xlog("next response from mongodb is [[$mongodb(mgr1=>value)]]\n");
  247. }
  248. }
  249. mongodb_free("mgr1");
  250. ...
  251. </programlisting>
  252. </example>
  253. </section>
  254. <section id="ndb_mongodb.f.mongodb_free">
  255. <title>
  256. <function moreinfo="none">mongodb_free(replyid)</function>
  257. </title>
  258. <para>
  259. Frees data in a previous reply from memory.
  260. After this function call, accessing to a freed replyid returns null value.
  261. </para>
  262. <para>
  263. It is not really necessary to free a reply to use it again in a new mongodb_cmd
  264. function, being automatically freed on next command execution, but for freeing
  265. used resources (e.g., memory), it is recommended to do it.
  266. </para>
  267. <example>
  268. <title><function>mongodb_free</function> usage</title>
  269. <programlisting format="linespecific">
  270. ...
  271. if(mongodb_cmd_simple("mgs1", "kamailio", "acc", "{ \"collStats\": \"acc\" }", "mgr1")) {
  272. xlog("response from mongodb is [[$mongodb(mgr1=>value)]]\n");
  273. }
  274. mongodb_free("mgr1");
  275. ...
  276. </programlisting>
  277. </example>
  278. </section>
  279. </section>
  280. </chapter>