我正在尝试使用两个MongoDB数据源进行 StrongLoop Loopback 复制。在电话数据库中发布一些数据后,出现此错误。
TypeError:无法在 Function.PersistedModel.replicate 调用未定义的方法“getChangeModel”(/home/dchavez/Media/projects/SyncTest/node_modules/loopback/lib/models/persisted-model.js:726:34)
数据保存在 Phone 集合中,但由于错误,它没有被复制到 Repo 集合中。
这些是我的模型配置。
手机型号
{
"name": "Phone",
"plural": "Phones",
"base": "PersistedModel",
"strict": false,
"idInjection": true,
"options": {
"trackChanges": true
},
"properties": {
"id": {
"type": "string",
"id": true
},
"num": {
"type": "string"
},
"name": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
回购模型
{
"name": "Repo",
"plural": "Repos",
"base": "PersistedModel",
"strict": false,
"idInjection": true,
"properties": {
"name": {
"type": "string"
},
"num": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
我的数据源配置是这样的:
{
"db": {
"name": "db",
"connector": "memory"
},
"MongoDb": {
"host": "localhost",
"port": 27017,
"database": "PhoneDb",
"name": "MongoDb",
"connector": "mongodb"
}}
电话,js是这个
module.exports = function(Phone) {
var loopback = require('../..');
var Repo = loopback.Repo;
var conflicts;
Phone.on('changed', function(obj) {
replicateSourceToTarget();
resolveAllConflicts();
});
function replicateSourceToTarget() {
Phone.replicate(0, Repo, {}, function(err, replicationConflicts) {
conflicts = replicationConflicts;
});
}
function resolveAllConflicts() {
if (conflicts.length) {
conflicts.forEach(function(conflict) {
conflict.resolve();
});
}
}
};