{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/128","repository_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb","labels_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/128/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/128/comments","events_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/128/events","html_url":"https://github.com/strongloop/loopback-connector-mongodb/issues/128","id":70085513,"number":128,"title":"PrincipleId stored as string in Rolemapping model","user":{"login":"paulJordaan","id":4620184,"avatar_url":"https://avatars.githubusercontent.com/u/4620184?v=3","gravatar_id":"","url":"https://api.github.com/users/paulJordaan","html_url":"https://github.com/paulJordaan","followers_url":"https://api.github.com/users/paulJordaan/followers","following_url":"https://api.github.com/users/paulJordaan/following{/other_user}","gists_url":"https://api.github.com/users/paulJordaan/gists{/gist_id}","starred_url":"https://api.github.com/users/paulJordaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulJordaan/subscriptions","organizations_url":"https://api.github.com/users/paulJordaan/orgs","repos_url":"https://api.github.com/users/paulJordaan/repos","events_url":"https://api.github.com/users/paulJordaan/events{/privacy}","received_events_url":"https://api.github.com/users/paulJordaan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-22T10:20:08Z","updated_at":"2016-02-03T17:28:39Z","closed_at":null,"body":"When assigning a role to a user as per the ACL example the principleId field in the Rolemapping model is stored as a string in mongodb. This causes all of the role related functionality to break. When manually changing the principleId to the objectId type it fixes the problem. How can I fix this via code?\r\n```\r\ncreatedRole.principals.create({\r\n\tprincipalType: RoleMapping.USER,\r\n\tprincipalId: createdUser.id\r\n}, function(err, rolePrincipal) {```"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/comments/179362122","html_url":"https://github.com/strongloop/loopback-connector-mongodb/issues/128#issuecomment-179362122","issue_url":"https://api.github.com/repos/strongloop/loopback-connector-mongodb/issues/128","id":179362122,"user":{"login":"alFReD-NSH","id":822510,"avatar_url":"https://avatars.githubusercontent.com/u/822510?v=3","gravatar_id":"","url":"https://api.github.com/users/alFReD-NSH","html_url":"https://github.com/alFReD-NSH","followers_url":"https://api.github.com/users/alFReD-NSH/followers","following_url":"https://api.github.com/users/alFReD-NSH/following{/other_user}","gists_url":"https://api.github.com/users/alFReD-NSH/gists{/gist_id}","starred_url":"https://api.github.com/users/alFReD-NSH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alFReD-NSH/subscriptions","organizations_url":"https://api.github.com/users/alFReD-NSH/orgs","repos_url":"https://api.github.com/users/alFReD-NSH/repos","events_url":"https://api.github.com/users/alFReD-NSH/events{/privacy}","received_events_url":"https://api.github.com/users/alFReD-NSH/received_events","type":"User","site_admin":false},"created_at":"2016-02-03T17:28:39Z","updated_at":"2016-02-03T17:28:39Z","body":"There's two ways, to fix this.\r\n\r\n- Make sure when inserting roleMappings, the principalId is ObjectId. Right now there are multiple places in loopback's code that will convert the principalId to string, and this seems to me it is by design, so I guess this is not possible.\r\n- On queries make sure when principalId is not converted to ObjectId. This is fixed in #67, but not merged, due to unresolved compatibility issues and now it's outdated."}}