我想在Node.js中使用waterline-orientdb包創建一個簡單的服務器應用程序,其中有幾個用戶可以調用多個方法。在用戶可以做任何事情之前,用戶需要使用他的用戶名和密碼進行身份驗證。在這個身份驗證中,用戶對象被賦予一個將被未來請求捎帶的令牌。 向用戶授予令牌時,會調用更新查詢。當調用更新請求我收到以下錯誤:Node.js waterline-orientdb更新失敗
ERROR err: { [OrientDB.RequestError: expression item ']' cannot be resolved because current record is NULL]
name: 'OrientDB.RequestError',
message: 'expression item \']\' cannot be resolved because current record is NULL',
data: {},
previous: [],
id: 1,
type: 'com.orientechnologies.orient.core.exception.OCommandExecutionException',hasMore: 0 }
奇怪的是,該更新被執行,那麼這個錯誤不會對更新請求的影響。但是因爲我想抓住所有的錯誤,所以我不能忽視這一點。
我的模型看起來是這樣的:
module.exports = {
tableName: 'User',
identity: 'dbuser',
schema: true,
attributes: {
id: {
type: 'string',
primaryKey: true,
columnName: '@rid'
},
username: {
type: 'string',
required: true,
unique: true
},
password: {
type: 'string',
required: false
},
token: {
type: 'string'
},
follows: {
collection: 'dbuser',
via: 'followed',
dominant: true
},
followed: {
collection : 'dbuser',
via: 'follows'
}
};
正如你所看到的,我的兩個用戶海誓山盟關聯,這樣一個用戶可以跟隨其他用戶的活動。當我刪除關聯(如下和之後)時,錯誤也消失。
的一段代碼,其中更新偏偏喜歡這個樣子:
user[0].token = generateToken(user[0])
dbuser.update({
id: user[0].id
}, user[0]).exec(function (error, data) {
if (error) res.json(401, {
code: 401,
error: "Token could not be updated"
})
res.json(user);
});
有沒有人有關於如何避免此行爲或錯誤甚至什麼手段的想法?
你從哪裏得到這個錯誤嗎?在orientdb或res.json中的變量錯誤?最後一段代碼沒有說明用戶[0]或數據庫中存在什麼數據,以及已經存在的關係。也許登錄用戶[0],看看你想要保存的是什麼。代碼很難閱讀。沒有人會嘗試閱讀,格式化它。你缺少';'在相當多的幾行中,如果你通過jslint運行你的代碼,你會得到一些很好的提示。你有沒有找到解決方案? – oldwizard 2015-02-02 09:40:49