使用 ActiveRecord 将 MongoDB 网格 ID 序列化为字符串
在我的 Sinatra 应用程序中,我使用带有 Grid 的 MongoDB 在 Heroku 上存储书籍封面。我希望能够将这些与我的 ActiveRecord 驱动的主数据库中的书籍相关联。目前,我正在从 Google Books 下载图像,将其存储在 MongoDB 中,并将 BSON::ObjectID 对象作为字符串存储到数据库中。
然而,当我去检索图像时,网格不会接受此字符串作为获取文件的方式。
有没有更好的方法来存储这些信息或者更好的方法来关联两个数据库之间的数据?
In my Sinatra app, I'm using a MongoDB with Grid to store book covers on Heroku. I want to be able to associate these with the books in my ActiveRecord-driven primary database. Currently, I'm downloading the image from Google Books, storing it in the MongoDB, and storing the BSON::ObjectID object into the database as a string.
When I go to retrieve the image, however, grid won't accept this string as a way to get the file.
Is there a better way for me to store this information or a better way for me to associate data between the two databases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一位朋友帮我解决了这个问题:它是一个 YAML 字符串,因此
将字符串存储在数据库中就可以了。
A friend helped me with this one: it was a YAML string, so
on the string being stored in the database did the trick.