Node.JS MongoDB 操作顺序用例
mongodb-native 驱动程序的操作顺序是什么?
假设您有一个类,其目的是保存某种文档,并且它的寿命很长。应该调用多少次 open ?每个数据库写入一次?什么时候应该调用 close ?本质上我想要一个如下所示的类方法:
var myMongoClass = new MongoDB(server,port)
myMongoClass.write_file(filename,callback)
myMongoClass.write_doc(doc,callback)
我不久前发布了这个并让它工作: MongoDB GridFS 使用 Node.JS 保存文件时出现问题
现在它根本无法工作,并因 TypeError: Cannot read property 'md5' of null
失败。
每次我使用这个库时,我都想用头撞墙。
What is the order of operations for the mongodb-native driver?
Let's say you have a class that's purpose is to save a document of some sort and let's say it has a long life. How many times should open be called? Once per db write? When is close supposed to be called? Essentially I want a class method that looks like this:
var myMongoClass = new MongoDB(server,port)
myMongoClass.write_file(filename,callback)
myMongoClass.write_doc(doc,callback)
I posted this a while ago and got it working:
Problem with MongoDB GridFS Saving Files with Node.JS
It's now not working at all and failing with TypeError: Cannot read property 'md5' of null
Every time I work with this library I want to bang my head through a wall.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎正确的答案是创建一个客户端并在应用程序期间保持该客户端打开(从不显式调用关闭)。我有一个包装器,它保留对连接的客户端的引用,并且我的应用程序仅在收到连接时启动。
It seems like the correct answer is create a client and keep that client open for the duration of the application (never explicitly calling close). I have a wrapper that keeps a reference to the connected client and my app only boots up if the connection is received.