mongodbmodel-view-controllererlangchicagobossnosql

ChicagoBoss doesn't seem to be saving the right values into MongoDB


So I've worked my way through an evening with ChicagoBoss. I am now currently trying to wire up ChicagoBoss with MongoDB to build an app with it (and learn two new technologies I've been eyeing in the process). Unfortunately I seem to have hit a snag. Specifically, after a user is created, the password does not appear to be what it was set to. Please note that with the exception of configuration code, all code comes directly from the Chicago Boss tutorials.

boss.config - re Databases:

 {db_host, "localhost"},
 {db_port, 27017},
 {db_adapter, mongodb},

login function

 login('POST', []) ->
   Name = Req:post_param("name"),
   case boss_db:find(user, [{name, Name}]) of
     [User] ->
       case User:check_password(Req:post_param("password")) of
         true ->
           {redirect, proplists:get_value("redirect",
            Req:post_params(), "/"), User:login_cookies()};
         false ->
          {ok, [{error, "Bad name/password combination"}]}
        end;
     [] ->
       {ok, [{error, "No User named " ++ Name}]}
   end.

Then - after creating a user from the admin interface and using

   hash_for(Name, Password) ->
      Salt = mochihex:to_hex(erlang:md5(Name)),
      hash_password(Password, Salt).

to generate a hash, the following two things happen:

1) The user is created but not id-ed as user-1, but rather as usr-51970a2a3e01c027d4000001.

Why is that? I thought ChicagoBoss followed the rails convention of autoincrementing numeric indices?

2) Even though the password that was passed into hash_for is used, the user can never login.

3) After the Chicago Boss server is restarted the newly created database objects are retained - so mongo is at least saving something correctly.

Can anyone shed any light on whats going on here? How is MongoDB trying to save the user? What is the correct method for wiring up Chicago Boss with MongoDB, does boss_db not handle MongoDB natively?

The tutorial all of this is trying to use as a jump off point is:

https://github.com/evanmiller/ChicagoBoss/wiki/An-Evening-With-Chicago-Boss


Solution

  • MongoDB is indeed supported in Chicago Boss, but some things will be different with MongoDB as compared to a SQL database. In particular, because it is "humongous", MongoDB uses UUIDs instead of auto-incrementing IDs. This allows the creation of new documents without keeping a centralized counter. So that explains why the ID is "usr-51970a2a3e01c027d4000001" and not "usr-1".

    As for the password issue, I think the next step is to add debug printing statements. What hash value is the DB expecting? Is the DB saving the correct hash value? If you created the user through the admin interface there is potential for slight errors such as an extra newline in the password.

    Also, feel free to ping us on the mailing list or on IRC at any time.