回送hasMany关系在mongodb上不起作用 [英] Loopback hasMany relation doesn't work on mongodb
问题描述
从RedHat linux迁移到AWS上的SUSE之后,我有一些奇怪的行为.
I have some strange behavior after moving from RedHat linux to SUSE on AWS.
之前一切正常.
这是我的关系:
类别:
{
"name": "Category",
"plural": "categories",
"base": "PersistedModel",
"relations": {
...
"professions": {
"type": "hasMany",
"model": "Profession",
"foreignKey": ""
}
}
}
专业
{
"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" : "..."
}
当我请求/api/categories/{id}/professions
It doesn't work when I request /api/categories/{id}/professions
但是/api/profession/{id}/category可以正常工作.
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({名称:"TEST2"});也可以正常工作.
Category.professions.create({ name: "TEST2" }); Works fine as well.
我在AWS上使用RedHat linux.现在,我在AWS上使用SUSE linux.
I was using RedHat linux on AWS. Now I am using SUSE linux on AWS.
Mongo数据库版本:数据库版本v3.0.7
Mongo db version : db version v3.0.7
node --version
v5.4.1
npm --version
3.3.12
npm list loopback
`-- loopback@2.26.2
我试图通过/explorer面板和代码对其进行更新.
I tried to update it from /explorer panel and code.
在代码中(角度),我这样做:
in code (angular) I do this:
Profession.prototype$updateAttributes(
{
id: toAdd[i]
},
{
categoryId: catId
});
正如我所说,所有代码都可以在运行RDHE的测试服务器上运行. 我将检查mongo日志,但我安装了相同的mongo版本并使用相同的mongo.config
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
推荐答案
Okey ...所以问题出在以下两个模块之一或两个:
Okey... so the problem was one or both of these modules:
"loopback-connector-mongodb": "^1.13.0"
"loopback-datasource-juggler": "^2.39.0"
由于版本号写为^#.#.#,表示版本更高但兼容. 但是其中之一无法正常工作: https://github.com/strongloop/loopback/issues/274
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
这引起了所有问题.
简单的解决方案:
"loopback-connector-mongodb": "1.13.0"
"loopback-datasource-juggler": "2.39.0"
我刚刚安装了我知道可以使用的版本.
I just installed the versions which i know that works.
这篇关于回送hasMany关系在mongodb上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!