MongoDB GridFS.findOne 在结果有效之前可能存在延迟?
在我的应用程序中,我调用
GridFSDBFile f = gfs.findOne (new ObjectId(gridId))
This 通常会返回一个之前通过调用创建的有效文件
GridFSInputFile gridFile = gfs.createFile(someFile.getBytes())
gridFile.save()
但有时它会返回 null。所以我把它放在一个 while 循环中,
while (!f)
{
f = gfs.findOne(new ObjectId(gridId))
Thread.sleep(200)
}
在大约 400 毫秒过去后第二次调用后,这将返回一个有效文件。我是否做错了什么,或者文件创建后到您可以访问它的时间是否可能存在延迟?
In my application I'm calling
GridFSDBFile f = gfs.findOne (new ObjectId(gridId))
This usually returns a valid file that was previously created by a call to
GridFSInputFile gridFile = gfs.createFile(someFile.getBytes())
gridFile.save()
But sometimes it returns null. So I put it in a while loop
while (!f)
{
f = gfs.findOne(new ObjectId(gridId))
Thread.sleep(200)
}
This returns a valid file after the second call after about 400 ms have elapsed. Am I doing something wrong or is there a possible delay after a file is created to the time you can access it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 http://groups.google.com/group 相同/mongodb-user/browse_thread/thread/9b90135104b1bdeb?pli=1 并已由 10gen 人员回答 - 不知道为什么这个问题必须发布在不同的平台上,其中 mongo 用户列出了可能的最佳平台从官方维护者那里获得帮助。
Identical with http://groups.google.com/group/mongodb-user/browse_thread/thread/9b90135104b1bdeb?pli=1 and already answered there by the 10gen people - not sure why this question must be posted on a different platform where the mongo users list the likely the best platform for getting help from the official maintainers.