Firebase事务处理错误:[错误:设置]

时间:2016-07-07 16:15:57

标签: javascript firebase firebase-realtime-database

我正在尝试在后台从我的节点应用程序增加“view_amount”的值,但它只有一半的时间才会工作。另一半,我得到这个错误:

[Error: set]

这是我的代码(Coffeescript):

@ref.firebaseClient.child('listings').child(val.listing_id).child("view_amount").transaction (current_value) ->
  (current_value || 0) + 1
, (error, committed, snapshot) ->
  if error
    console.log error

这就是我设置它的路径:

{
  "headline" : "Yeezy Boost 750",
  "shoe_size" : 9.5,
  "short_url" : "K5wv",
  "size_type" : "men",
  "status" : "active",
  "style_code" : "BB1840",
  "timestamp" : 1467842400000,
  "view_amount" : 3043,
  "watching_amount" : 2
}

什么可能导致交易代码失败?我是否有可能在特定路径上每秒运行一次交易次数太多?如果我在运行事务的同时更改“style_code”,事务是否会失败?

更新:这是我在Node工作中遇到的错误。我发现“设置”错误非常混乱,因为我正在尝试在路径“view_amount”上执行事务。我决不在那条路上做“设定”。

Aug 17 12:15:44 Worker app/worker.1:  error:    Error: set 
Aug 17 12:15:44 Worker app/worker.1:    at Error (native) 
Aug 17 12:15:44 Worker app/worker.1:    at hi (/app/node_modules/firebase/database-node.js:222:395) 
Aug 17 12:15:44 Worker app/worker.1:    at Yh (/app/node_modules/firebase/database-node.js:220:351) 
Aug 17 12:15:44 Worker app/worker.1:    at /app/node_modules/firebase/database-node.js:220:286 
Aug 17 12:15:44 Worker app/worker.1:    at /app/node_modules/firebase/database-node.js:145:167 
Aug 17 12:15:44 Worker app/worker.1:    at Dg.h.ud (/app/node_modules/firebase/database-node.js:146:104) 
Aug 17 12:15:44 Worker app/worker.1:    at rg.ud (/app/node_modules/firebase/database-node.js:137:364) 
Aug 17 12:15:44 Worker app/worker.1:    at Xf.eg (/app/node_modules/firebase/database-node.js:135:280) 
Aug 17 12:15:44 Worker app/worker.1:    at $f (/app/node_modules/firebase/database-node.js:123:109) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].Ka.onmessage (/app/node_modules/firebase/database-node.js:121:467) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].EventTarget.dispatchEvent (/app/node_modules/firebase/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js:22:30) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].instance._receiveMessage (/app/node_modules/firebase/node_modules/faye-websocket/lib/faye/websocket/api.js:134:10) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].<anonymous> (/app/node_modules/firebase/node_modules/faye-websocket/lib/faye/websocket/api.js:34:49) 
Aug 17 12:15:44 Worker app/worker.1:    at emitOne (events.js:82:20) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].emit (events.js:169:7) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].<anonymous> (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:451:14) 
Aug 17 12:15:44 Worker app/worker.1:    at pipe (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/pipeline/index.js:37:40) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].Pipeline._loop (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/pipeline/index.js:44:3) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].Pipeline.processIncomingMessage (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/pipeline/index.js:13:8) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].instance.processIncomingMessage (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/websocket_extensions.js:133:20) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].instance._emitMessage (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:442:22) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].instance._emitFrame (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:405:19) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].instance.parse (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:141:18) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].instance.parse (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/client.js:62:58) 
Aug 17 12:15:44 Worker app/worker.1:    at [object Object].IO.write (/app/node_modules/firebase/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/streams.js:80:16) 
Aug 17 12:15:44 Worker app/worker.1:    at TLSSocket.ondata (_stream_readable.js:528:20) 
Aug 17 12:15:44 Worker app/worker.1:    at emitOne (events.js:77:13) 
Aug 17 12:15:44 Worker app/worker.1:    at TLSSocket.emit (events.js:169:7) 
Aug 17 12:15:44 Worker app/worker.1:    at readableAddChunk (_stream_readable.js:146:16) 
Aug 17 12:15:44 Worker app/worker.1:    at TLSSocket.Readable.push (_stream_readable.js:110:10) 
Aug 17 12:15:44 Worker app/worker.1:    at TLSWrap.onread (net.js:523:20)

1 个答案:

答案 0 :(得分:3)

对于错误的错误消息表示歉意,但此错误表示您在相关路径(set()上方,上方或下方的任何内容)上执行了update()/listings/<val.listing_id>/view_amount操作交易已完成,因此我们取消了该交易,因为我们不知道我们是否应该在set()之前重新启动交易,或者set()是否应该覆盖交易&#39; s写等等。

通常,您需要注意不要在数据库的同一部分混合set()transaction()次调用。