Skip to content

Mongodb and remote connector issue #3394

Closed

Description

@davidrivers93

Hello.

We are using more than one loopback project using a microservices architecture connecting with each other using loopback remote connector. Finally, the database is mongodb.

On API1, we have the supplier model and on API2 we have the KmRange method which has a hasMany relation with supplier model.

The problem is that if I call to suppliers/:id/kmRanges I obtain an empty array although I have related data. I use an special property on each model to set an id as the loopback documentation says.

This is the supplier model.json :

{
"name": "Supplier",
"plural": "Suppliers",
"base": "PersistedModel",
"idInjection": false,
"forceId": false,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "string",
"generated": true,
"id": true
},
"name": {
"type": "string",
"required": true
},
"image": {
"type": "string"
},
"phone": {
"type": "string"
},
"addressLine1": {
"type": "string"
},
"addressLine2": {
"type": "string"
},
"city": {
"type": "string"
},
"region": {
"type": "string"
},
"country": {
"type": "string",
"default": "España"
},
"postalCode": {
"type": "string"
}
},
"validations": [],
"relations": {
"zones": {
"type": "hasMany",
"model": "Zone",
"foreignKey": ""
},
"rates": {
"type": "hasMany",
"model": "Rate",
"foreignKey": ""
},
"volumetricWeightRanges": {
"type": "hasMany",
"model": "VolumetricWeightRange",
"foreignKey": ""
},
"price": {
"type": "belongsTo",
"model": "price",
"foreignKey": "idSupplier"
},
"KmRange": {
"type": "hasMany",
"model": "KmRange",
"foreignKey": "idSupplier"
},
"routes": {
"type": "hasMany",
"model": "Route",
"foreignKey": "idSupplier"
},
"carrier": {
"type": "hasMany",
"model": "Carrier",
"foreignKey": "idSupplier"
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "*"
}
],
"methods": {}
}

And this is the kmRange model.json:

{
"name": "KmRange",
"plural": "KmRanges",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "string",
"generated": true,
"id": true
},
"min": {
"type": "number",
"required": true
},
"max": {
"type": "number",
"required": true
}
},
"validations": [],
"relations": {
"supplier": {
"type": "belongsTo",
"model": "Supplier",
"foreignKey": "idSupplier"
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "*"
}
],
"methods": {}
}

And finally, this a kmRange document on mongodb:

{ _id: ObjectId("590c7afd19ec56003cc97996"), min: NumberLong("100"), max: NumberLong("9999999"), supplierId: "590c7ad2beb2a70039aab8b2" }

If change on database an supplierId kmRange property to objectId, the get works:

{ _id: ObjectId("590c7afd19ec56003cc97997"), min: NumberLong("50"), max: NumberLong("100"), supplierId: ObjectId("590c7ad2beb2a70039aab8b2") }

Thanks in advance.

David

Activity

  1. davidrivers93 commented on May 22, 2017

    @davidrivers93
    Author

    Any idea?

  2. stale commented on Aug 23, 2017

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  3. stale commented on Sep 6, 2017

    @stale

    This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions