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