4
votes

When adding new users to Couchdb, is it appropriate to add extra profile fields to the same document?

I know I could have another db with user profiles in it to supplement what is in the _users documents, but is the design of the _users documents static, or would it be ok to add additional fields to the users documents?

1

1 Answers

3
votes

The _users database is a great place to store information about users. The design of the documents is relaxed, so I would not worry about adding fields. (Removing some could be risky though.) You could consider adding an object in the document for all your data:

{ "_id": "org.couchdb.user:jhs"
, "_rev": "3-281e87af31d7d8277463732dccc06f65"
, "name": "jhs"
, "type": "user"
, "roles": ["whatever"]
// (etc.)
, "myapp":
  { "profile_photo": "http://example.com/some_photo.png"
  , "favorite_color": "blue"
  }
}

The one thing you want to check is the validate_doc_update function in _design/_auth. Make sure it is not going to prevent you from doing what you need. Currently (probably indefinitely) it does not check any attributes in the document besides those it needs (type, name, roles, etc.).

Just remember that these documents are world-readable. Per-user private data should go in a per-user private database.