I am looking into the Apostrophe CMS for a way to embed data into the mongoDB user documents so that I can keep more data about a given user beyond just their username, password, and role (admin, guest, contributor, etc).
Looking through the Apostrophe CMS version 3 documentation (https://v3.docs.apostrophecms.org/guide/users.html) there seems to be no information about how to interact with the database so that more data can be added to a user. As it stands there don't seem to be any methods available to interact with the database in this fasion.
An example might be:
user: {
role: guest,
group: eastUS,
groupID: 1jfe25226,
isActive: true,
hasBeenContacted: true
}
If anyone has attempted to do this or successfully achieved this please let me know your approach.
Apostrophe users are just Apostrophe pieces. That means you can extend them with custom fields in a project-level modules/@apostrophecms/user/index.js
file, just like you would add fields to any piece type. This gives you a way to add additional editable fields.
The documentation on queries also applies to users. However bear in mind that for security reasons only admins can query for users or update them.
To update a single custom property of the current user you might write the following inside an Apostrophe apiRoute
, promise event handler, etc.:
await self.apos.doc.db.update({ _id: req.user._id }, { $set: { group: 'xyz' } });
This goes directly to MongoDB to $set
one property and bypasses permissions checks, so use with care.
Apostrophe's standard REST APIs also work for users, but bear in mind that for security reasons only an admin user can fetch and edit users.
I can revise and add more clarification if you can be more specific about what you are trying to do and in what situation.