database design - Storing an array of searchable values in MongoDB -
i need store role id , role name in each document in users
collection. need able "get users have xyz role" or "get users have role who's name contains 'xyz'", stuff that.
is possible in mongo?
right now, i'm storing data this:
{ "_id": { "$id": "4fe30e3db92f5d2a5c000000" }, "alias": "rogue_coder", "display_name": "rogue coder", "email": "rogue@example.com", "roles": { "4fe30e5fb92f5d6f53000000": "super administrator" } }
with that, can see if user has given role, can't users have role contains word "super" example. ideas on how this?
based on attempting do, may have store role_id & role_name in separate arrays, such:
{ "_id": { "$id": "4fe30e3db92f5d2a5c000000" }, "alias": "rogue_coder", "display_name": "rogue coder", "email": "rogue@example.com", "role_names": [ "super administrator" ], "role_ids" : [ "4fe30e5fb92f5d6f53000000" ] }
Comments
Post a Comment