我正在创建一个与 MongoDB 接口的自定义组件。我编写了一个连接到 MongoDB 的 CoffeeScript 文件,并将其存储在 noflo/components 文件夹中。
MongoBase.coffee
noflo = require "noflo"
mongodb = require "mongodb"
url = require "url"
class exports.MongoBase extends noflo.Component
constructor: ->
super
@inPorts =
url: new noflo.Port()
@inPorts.url.on "data", (data) =>
try
@parseConnectionString(data)
@MongoClient = mongodb.MongoClient;
@MongoClient.connect @serverUrl, (err, db) ->
if err
console.log("Error in connecting to MongoDB")
else
console.log("Connected to MongoDB")
catch error
console.log(error)
parseConnectionString: (connectionString) =>
databaseUrl = try
url.parse(connectionString)
catch error
console.log(error)
[..., @serverUrl, @databaseName] = databaseUrl.split('/')
@serverUrl = "mongo://" + @serverUrl
我将以下条目添加到 component.json
"MongoBase": "components/MongoBase.coffee"
除此之外,我还创建了一个 mongo.fbp 文件来检查组件的流程。FBP 文件具有以下代码:
'mongodb://localhost:27017/test' -> url DocReader(MongoBase)
在运行noflo mongo.fbp
时,我收到以下错误:
/home/saurabh/workspace/noflo/node_modules/fbp/lib/fbp.js:1628
edges.forEach(function (o, i) {
^
TypeError: Object #<Object> has no method 'forEach'
at Object.parser.registerEdges (/home/saurabh/workspace/noflo/node_modules/fbp/lib/fbp.js:1628:15)
at peg$c25 (/home/saurabh/workspace/noflo/node_modules/fbp/lib/fbp.js:60:50)
at peg$parseline (/home/saurabh/workspace/noflo/node_modules/fbp/lib/fbp.js:749:30)
at peg$parsestart (/home/saurabh/workspace/noflo/node_modules/fbp/lib/fbp.js:282:12)
at Object.parse (/home/saurabh/workspace/noflo/node_modules/fbp/lib/fbp.js:1650:18)
at Object.exports.loadFBP (/home/saurabh/workspace/noflo/lib/Graph.js:1065:33)
at /home/saurabh/workspace/noflo/lib/Graph.js:1116:24
at fs.js:268:14
at Object.oncomplete (fs.js:107:15)
我的代码有问题,或者我用来运行代码的步骤有问题吗?