我正在尝试在 Node.js 环境中运行 Mosca MQTT 代理,其 MongoDB 后端位于 Microsoft 的 Azure 云中。DocumentDB 存储有一个 MongoDB API。
首先,我从 Mosca 网站https://github.com/mcollina/mosca/wiki/Mosca-basic-usage#lets-put-it-all-together-now复制了示例代码
var mosca = require('mosca')
var ascoltatore = {
type: 'mongo',
url: 'mongodb://localhost:27017/mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
};
var moscaSettings = {
port: 1883,
backend: ascoltatore,
persistence: {
factory: mosca.persistence.Mongo,
url: 'mongodb://localhost:27017/mqtt'
}
};
var server = new mosca.Server(moscaSettings);
server.on('ready', setup);
server.on('clientConnected', function(client) {
console.log('client connected', client.id);
});
server.on('published', function(packet, client) {
console.log('Published', packet.payload);
});
function setup() {
console.log('Mosca server is up and running')
}
...这适用于本地安装的 MongoDB 服务器。
然后我用url:
可以从 Azure 门户获取的 Node.js 连接字符串替换了这两个匹配项。之后,与 Azure DocumentDB 的连接失败并出现以下错误:
$ node index.js
/[...]/node_modules/mongodb/lib/utils.js:98
process.nextTick(function() { throw err; });
^
Error: Cannot recover. Collection is not capped.
at /[...]/node_modules/ascoltatori/lib/mongo_ascoltatore.js:241:26
at handleCallback (/[...]/node_modules/mongodb/lib/utils.js:95:56)
at /[...]/node_modules/mongodb/lib/collection.js:1559:5
at handleCallback (/[...]/node_modules/mongodb/lib/utils.js:95:56)
at /[...]/node_modules/mongodb/lib/collection.js:1528:5
at handleCallback (/[...]/node_modules/mongodb/lib/utils.js:95:56)
at /[...]/node_modules/mongodb/lib/cursor.js:852:16
at handleCallback (/[...]/node_modules/mongodb-core/lib/cursor.js:171:5)
at setCursorDeadAndNotified (/[...]/node_modules/mongodb-core/lib cursor.js:506:3)
at nextFunction (/[...]/node_modules/mongodb-core/lib/cursor.js:652:7)
at Cursor.next [as _next] (/[...]/node_modules/mongodb-core/lib cursor.js:693:3)
at fetchDocs (/[...]/node_modules/mongodb/lib/cursor.js:848:10)
at /[...]/node_modules/mongodb/lib/cursor.js:871:7
at handleCallback (/[...]/node_modules/mongodb-core/lib/cursor.js:171:5)
at nextFunction (/[...]/node_modules/mongodb-core/lib/cursor.js:683:5)
at /[...]/node_modules/mongodb-core/lib/cursor.js:594:7
at queryCallback (/[...]/node_modules/mongodb-core/lib/cursor.js:253:5)
at /[...]/node_modules/mongodb-core/lib/connection/pool.js:457:18
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
知道这里会缺少什么吗?