Loopback hasMany relation doesn't work on mongodb

时光总嘲笑我的痴心妄想 提交于 2020-01-14 03:36:26

问题


I have some strange behavior after moving from RedHat linux to SUSE on AWS.

Everything was working fine, before.

Here is my relations:

Category:

{
    "name": "Category",
    "plural": "categories",
    "base": "PersistedModel",
    "relations": {
      ...
      "professions": {
        "type": "hasMany",
        "model": "Profession",
        "foreignKey": ""
      }
    }
 }

Profession:

{
    "name": "Profession",
    "plural": "professions",
    "base": "PersistedModel",
    "relations": {
      ...
      "category": {
        "type": "belongsTo",
        "model": "Category",
        "foreignKey": ""
      }
    }
 }

The problem is that when I update an existing profession with:

{
     "categoryId" : "..."
}

It doesn't work when I request /api/categories/{id}/professions

But /api/profession/{id}/category works fine.

Also if I create new Profession like:

{
     "name" : "TEST",
     "categoryId" : "..."
}

It works fine both ways.

Category.professions.create({ name: "TEST2" }); Works fine as well.

I was using RedHat linux on AWS. Now I am using SUSE linux on AWS.

Mongo db version : db version v3.0.7

EDIT:

node --version
v5.4.1

npm --version
3.3.12

npm list loopback
`-- loopback@2.26.2

EDIT:

I tried to update it from /explorer panel and code.

in code (angular) I do this:

Profession.prototype$updateAttributes(
{
    id: toAdd[i]
},
{
    categoryId: catId
});

And as I said, all the code works on test server running RDHE. I will check mongo logs, but I installed the same mongo version and using same mongo.config


回答1:


Okey... so the problem was one or both of these modules:

"loopback-connector-mongodb": "^1.13.0"
"loopback-datasource-juggler": "^2.39.0"

Since the version number is written as ^#.#.# it means higher but compatible. But one of them wasn't working: https://github.com/strongloop/loopback/issues/274

This caused all the problems.

Simple solution:

"loopback-connector-mongodb": "1.13.0"
"loopback-datasource-juggler": "2.39.0"

I just installed the versions which i know that works.



来源:https://stackoverflow.com/questions/35338292/loopback-hasmany-relation-doesnt-work-on-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!