User Tools

Site Tools


tutorials:kamailio-and-mongodb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
tutorials:kamailio-and-mongodb [2015/09/08 21:27]
miconda created
tutorials:kamailio-and-mongodb [2015/09/09 00:58]
miconda [Version Table]
Line 1: Line 1:
 ====== Kamailio and MongoDB ====== ====== Kamailio and MongoDB ======
  
-====== Kamailio Database ======+Details about how to use Kamailio with a MongoDB backend. 
 +===== Kamailio Database =====
  
 The **use** command in mongodb client **mongo** creates the database if it doesn't exit: The **use** command in mongodb client **mongo** creates the database if it doesn't exit:
Line 18: Line 19:
 Note that a database is not shown by the above command if it is empty -- you need to add some records to it. Note that a database is not shown by the above command if it is empty -- you need to add some records to it.
  
-===== Version Table =====+==== Version Table ====
  
 Kamailio uses version table to check if the structure of a database table has the structure version the C code expects. Kamailio uses version table to check if the structure of a database table has the structure version the C code expects.
Line 37: Line 38:
 </code> </code>
  
-==== Version Table Records ====+=== Version Table Records ===
  
 Add the records for the other Kamailio tables you are going to use. Some examples: Add the records for the other Kamailio tables you are going to use. Some examples:
Line 51: Line 52:
 > db.getCollection("version").insert({table_name: "watchers", table_version: NumberInt(3) }) > db.getCollection("version").insert({table_name: "watchers", table_version: NumberInt(3) })
  
-db.getCollection("version").insert({table_name: "active_watchers", table_version: NumberInt(11) })+db.getCollection("version").insert({table_name: "active_watchers", table_version: NumberInt(11) })
  
 </code> </code>
  
-===== Other Tables =====+To learn what is the version number for a specific table, look inside **lib/srdb1/schema/**, there is an xml file with the name of the table and inside it you should see the **version** attribute.
  
-MongoDB doesn't have a schema definition for documents stored in a collection.+==== Other Tables ====
  
 +MongoDB doesn't have a schema definition for documents stored in a collection. It is not required to create a collection before inserting a record to it.
 +
 +Anyhow, if you want, you can create the collections in advance, using:
 +
 +<code>
 +> db.createCollection("tablename")
 +</code>
 +===== Kamailio Config =====
 +
 +==== DB URL ====
 +
 +The corresponding database URL in kamailio.cfg:
 +
 +  * if MongoDB is on local host and there is no username and password to connect to it:
 +
 +<code>
 +#!define DBURL "mongodb://localhost/kamailio"
 +</code>
 +
 +  * if MongoDB is on local host and there is an username and password to connect to it:
 +
 +<code>
 +#!define DBURL "mongodb://username:password@localhost/kamailio"
 +</code>
 +
 +==== Other Parameters ====
 +
 +If you store location records in MongoDB, set the following parameter for usrloc modules:
 +
 +<code>
 +modparam("usrloc", "db_insert_null", 1)
 +</code>
tutorials/kamailio-and-mongodb.txt · Last modified: 2019/01/07 09:24 by henningw