User Tools

Site Tools


This is an old revision of the document!

Kamailio and MongoDB

Kamailio Database

The use command in mongodb client mongo creates the database if it doesn't exit:

# mongo
> use kamailio

To display the databases, you can use:

> show dbs

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

Kamailio uses version table to check if the structure of a database table has the structure version the C code expects.

A table is MongoDB is named collection. To create the collection version, do:

> db.createCollection("version")

List the existing collections in the current database:

> show collections

Version Table Records

Add the records for the other Kamailio tables you are going to use. Some examples:

> db.getCollection("version").insert({table_name: "subscriber", table_version: NumberInt(6) })

> db.getCollection("version").insert({table_name: "location", table_version: NumberInt(8) })

> db.getCollection("version").insert({table_name: "presentity", table_version: NumberInt(4) })

> db.getCollection("version").insert({table_name: "watchers", table_version: NumberInt(3) })

db.getCollection("version").insert({table_name: "active_watchers", table_version: NumberInt(11) })

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.

Other Tables

MongoDB doesn't have a schema definition for documents stored in a collection.

DB URL in Kamailio Config

The corresponding database URL in kamailio.cfg:

  • if MongoDB is on local host and there is no username and password to connect to it:
#!define DBURL "mongodb://localhost/kamailio"
  • if MongoDB is on local host and there is an username and password to connect to it:
#!define DBURL "mongodb://username:password@localhost/kamailio"
tutorials/kamailio-and-mongodb.1441740749.txt.gz · Last modified: 2015/09/08 21:32 by miconda