Loopback AngularJS Get _id field from MongoDB Collection

190 Views Asked by At

Loopback AngularJS SDK and Get Data

I'm newer with Loopback.js

I have a lot of collection in MongoDB and I thought index field is the best way to relationship with two collection. For example,

I have two collections. These are Projects and Job

They have "ProjectID" table for hasMany relation. The project collection has many jobs. Look at this image.

enter image description here

This is other picture for create collection from loopback gui.

enter image description here

My question: I tried get _id field (it is also ProjectID) from database.Here is:

// Get Projects Data
if (typeof Projects.find({}) != "undefined") {
   $scope.projects = Projects.find({});
}

console.log($scope.projects);

But my result is in this picture :

enter image description here

Why I can't access _id or ProjectID ? Do I any mistake? If you know other good way for relation, you should tell me. Thank you for answers.

1

There are 1 best solutions below

0
On

I solved this problem.

You don't need to create other field for collection relation.

Delete all ID fields (like ProjectID, JobID, etc...) and use

slc loopback:relation

command. Thanks to this command create relation with own collection id.

The problem took my 5 hour, it maybe helpful other developer. Happy coding.