Mongomapper 使用名称引用数据库导致 ReferenceError 问题

发布于 2024-12-26 12:22:21 字数 390 浏览 2 评论 0原文

这是 Mongomapper 生成的查询:

MONGODB mydatabase['users'].find({:name=>"bob"}).limit(-1)

但这在 mongo 控制台中无效,因为正确的语法是

db.users.find({:name=>"bob"}).limit(-1)

如果我只使用生成的语法,我在控制台中收到此错误

Thu Jan 12 03:01:23 ReferenceError: mydatabase is not defined (shell):1

有什么方法可以使其正确吗?这导致我的 Rails 应用程序损坏。

This is the query generated by Mongomapper:

MONGODB mydatabase['users'].find({:name=>"bob"}).limit(-1)

But this is not valid in the mongo console since the correct syntax is

db.users.find({:name=>"bob"}).limit(-1)

If I just use the generated one, I got this error in the console

Thu Jan 12 03:01:23 ReferenceError: mydatabase is not defined (shell):1

Is there any way to make it correct? This causes my rails application broken.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

想念有你 2025-01-02 12:22:21

您不能在 MongoDB 控制台中使用符号,因为它们是 ruby​​ 而不是 javascript :-) 试试这个:

db.users.find({name: "bob"}).limit(-1)

You can't use symbols in the MongoDB console as they are ruby and not javascript :-) Try this:

db.users.find({name: "bob"}).limit(-1)
狠疯拽 2025-01-02 12:22:21

这不是mongodb的问题。 406 与控制器调用密切相关。

我需要使用:

render :json => @user

而不是

respond_to

It is not mongodb's issue. 406 is pretty much relating to the controller call.

I need to use:

render :json => @user

rather than

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