Ashwanth Madhav
Ashwanth Madhav

Reputation: 1134

Confusing with principalId in loopback Rolemapping

Confused with the principalId in Rolemapping. How to save it in the mongoDb . string or ObjectId.

Which is the correct method for saving it ?

{
"_id" : ObjectId("5d65f6efed4198ce6bc70d58"),
"principalType" : "USER",
"principalId" : ObjectId("5d65f6e9ed4198ce6bc70d57"),
"roleId" : ObjectId("5c74dbc3fe56e53b13b04fd7")
}

OR

{
"_id" : ObjectId("5d65f6efed4198ce6bc70d58"),
"principalType" : "USER",
"principalId" :"5d65f6e9ed4198ce6bc70d57",
"roleId" : ObjectId("5c74dbc3fe56e53b13b04fd7")
}

Upvotes: 0

Views: 56

Answers (1)

Jaspreet kaur
Jaspreet kaur

Reputation: 620

The correct method to save it is with ObjectId. As the table it is referencing will be having _id that is always a ObjectId default.

ObjectId, Number, String, and Buffer are valid for use as references. However, you should use ObjectId unless you are an advanced user and have a good reason for doing so.

Also if you want to populate this field(principalId), it also becomes easy if you have saved it with ObjectId.

Upvotes: 1

Related Questions