Create user with MongoDB

Joan Pujol
Added almost 3 years ago

I've download latest 7.1.0 nighty build and tried to configure to use MongoDB.

Tigase starts correctly but I can't login:

As I haven't found any documentation about how to create an user I just created a document in tig_users:

    "_id" : ObjectId("56f8508ba6629bcc4151c1c5"),
    "user_id" : "username@lujopmb.local",
    "domain" : "lujopmb.local",
    "password" : "mypassword"

Is this the way to create users? I've to create another entry?

Any documentation about that?

To be sure that the problem is in MongoDB I've verified that changing only --user-db-uri and --user-db to mysql configuration all works correctly.

Replies (2)

Added by Joan Pujol almost 3 years ago

I answer myself in case of someone has the same problem.

I had two problems:


_id is not an autogenerated field. It has to be a SHA256 of full user JID.

I solved that creating a small utility to create the user instead of creating the document manually:

    public static void main(String[] args) throws Exception {
        MongoRepository repository = new MongoRepository();
        repository.initRepository("mongodb://localhost:27017/tigase", new HashMap<>());

        BareJID user = BareJID.bareJIDInstance("username@lujopmb.local");
        boolean userExist = repository.userExists(user);
        if(userExist) {
            System.out.println("User already exists");
        } else {
            repository.addUser(user, "password");


With MySQL I only needed to specify --user-db but with MongoDB I found that --auth-db is also needed:

--user-db = tigase.mongodb.MongoRepository
--auth-db = tigase.mongodb.MongoRepository

With that two changes I've been able to authenticate without problems.

Added by Wojciech Kapcia TigaseTeam almost 3 years ago

You can safely include only --user-db-uri@, and as a result @--user-db and --auth-db values will be derived automatically.

It's best to utilize internal Tigase API (as you've did) or you can:

  • create new accounts using in-band-registration

  • (once admin account is present) use admin ad-hoc scripts to create new users (which will use same repository API)