使用 ActiveRecord 将 MongoDB 网格 ID 序列化为字符串

发布于 2024-09-15 12:53:08 字数 264 浏览 1 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱暴击 2024-09-22 12:53:08

一位朋友帮我解决了这个问题:它是一个 YAML 字符串,因此

YAML::load

将字符串存储在数据库中就可以了。

A friend helped me with this one: it was a YAML string, so

YAML::load

on the string being stored in the database did the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文