MongoDB驱动还需要promise吗?
Is it still necessary to promisify the MongoDB driver?
这个问题的答案是否仍然相关:How can I promisify the MongoDB native Javascript driver using bluebird?
我不知道这是什么时候更新的,但是 MongoDB 的 2.0 JS 驱动程序在选项对象 promiseLibrary
中有一个 属性:http://mongodb.github.io/node-mongodb-native/2.0/api/MongoClient.html
大多数 methods/functions 都会做出 return 承诺,例如 Cursor.toArray()
。
但是,我找不到使用这个新选项的示例,但是使用它不是更简单吗:
MongoClient.connect('mongodb://URL', { promiseLibrary: require('bluebird') });
或者这个定义有误? - 在这种情况下,应该如何正确定义?
更新:
代码是 运行 on io.js 所以我可能甚至不需要指定 promiseLibrary
因为驱动程序会使用 ES6 承诺? - 然而,据说 bluebird promises 更慢:
Why are native ES6 promises slower and more memory-intensive than bluebird?
更新2:
我已经添加了 bluebird 标签——如果 promisifying 真的比使用 MongoDB 自己的实现更好的话,也许从事 bluebird 工作的人可以提供更多细节?
Is it still necessary to promisify the MongoDB driver?
不,他们现在内置了对 bluebird 等 promise 库的支持。我认为我们应该以不同的方式提出问题:
Is it a good idea to promisify the MongoDB driver?
也许,bluebird 在将回调 API 转换为 promises 方面做得比 Mongo 驱动程序更轻松地在内部完成。仍然承诺 "in the before days".
可能会更快
这个问题的答案是否仍然相关:How can I promisify the MongoDB native Javascript driver using bluebird?
我不知道这是什么时候更新的,但是 MongoDB 的 2.0 JS 驱动程序在选项对象 promiseLibrary
中有一个 属性:http://mongodb.github.io/node-mongodb-native/2.0/api/MongoClient.html
大多数 methods/functions 都会做出 return 承诺,例如 Cursor.toArray()
。
但是,我找不到使用这个新选项的示例,但是使用它不是更简单吗:
MongoClient.connect('mongodb://URL', { promiseLibrary: require('bluebird') });
或者这个定义有误? - 在这种情况下,应该如何正确定义?
更新:
代码是 运行 on io.js 所以我可能甚至不需要指定 promiseLibrary
因为驱动程序会使用 ES6 承诺? - 然而,据说 bluebird promises 更慢:
Why are native ES6 promises slower and more memory-intensive than bluebird?
更新2: 我已经添加了 bluebird 标签——如果 promisifying 真的比使用 MongoDB 自己的实现更好的话,也许从事 bluebird 工作的人可以提供更多细节?
Is it still necessary to promisify the MongoDB driver?
不,他们现在内置了对 bluebird 等 promise 库的支持。我认为我们应该以不同的方式提出问题:
Is it a good idea to promisify the MongoDB driver?
也许,bluebird 在将回调 API 转换为 promises 方面做得比 Mongo 驱动程序更轻松地在内部完成。仍然承诺 "in the before days".
可能会更快