问题标签 [mongoid3]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby - 如何使用 mongoid / moped 进行 upsert / push
我正在使用 Mongoid (v3) 访问 MongoDB,并希望执行此操作:
这在 mongo shell 中运行良好。这也正是我想要的,因为它是一个单一的原子操作,这对我来说很重要,因为我会经常称呼它。我不想做两个操作——一个获取然后一个更新。我已经通过 mongoid 尝试了很多东西,但无法让它工作。
如何让 MongoID 不碍事,只需将此命令发送到 MongoDB?我猜想在 Moped 级别有一些方法可以做到这一点,但该库的文档基本上不存在。
mongoid - Mongoid 3 gem 依赖
我想将我的 mongoid gem 升级到 3.0,这样我就可以升级 activeadmin-mongoid 以获得新功能。
然而,我的 mongoid-mapreduce gem 依赖于 2.0。有没有解决的办法?有没有办法查看 mongoid-mapreduce 是否仍然可以使用 mongoid 3.0?
ruby-on-rails - mongoid where 与 has_many 关系
我有 3 个模型
城市.rb
地点.rb
以及具有我希望能够检查的属性状态的评论。
评论.rb
我希望能够调用 City.find("somecity").places
并且不显示所有地点,而是替换默认范围以仅查找具有“已发布”状态的评论的地点
在活动记录中,类似...
有没有办法在 mongoid 中做到这一点,或者我的第二个选择是将一个新属性合并到每当发表评论时设置为活动的位置。
ruby-on-rails - mongoid 将 has_many 关系转换为 embeds_many
不久前,我犯了早期的新手 mongodb 错误,并在我应该嵌入它们的时候创建了很多 has_many 关系。
我的问题是我现在如何将我的记录从多态 has_many 场景转换为 embeds_many?
到 =>
我通常会遍历所有记录并这样做,但我想命名将是一个问题。所以我不确定如何在不创建临时模型的情况下完成这一任务,但我希望其他一些人也犯了同样的错误并且可能有一个温和的解决方案?
ruby-on-rails - 无法在 ActiveAdmin 和 Mongoid 3.x 中保存自定义字段(数组)
我有一个字段“位置”,它是一个数组 [lng, lat]。
我在ActiveAdmin表单中有两个输入字段,定义如下
为了获得纬度和经度,我在模型中定义了两个吸气剂:
表单按预期显示。
为了保存这些值,我在模型中创建了两个 setter
在表单提交之后,这些方法被调用,但值不会被持久化。
我错过了什么吗?
ruby-on-rails-3 - MongoDB 错误与 Mongoid、Heroku、Device、MongoHQ 和 Rails
我正在开发一个当前部署到 heroku 的简单应用程序- 它使用 mongoid、设备并且可以在 localhost 中非常轻松地创建用户登录,但不能在 heroku 的生产环境中创建。可以尝试创建一个账号,提交后报错。
我认为我用于生产的 mongoid.yml 需要更改,但我不知道如何更改。
我heroku config
的有以下几点:
mongoid.yml 具有 Heroku 中建议的以下内容:
我的 gemfile 有以下内容:
在git push heroku master
它给了我以下提示之后:
heroku - Heroku 没有使用指定的 Ruby 1.9.3
升级到 Mongoid 3 和 Ruby 1.9.3。尝试在 Heroku Cedar Stack 上使用 Ruby 1.9.3。我在 Gemfile 的顶部添加了以下内容:
推送到 Heroku,它似乎正在工作
-----> Heroku 接收推送
-----> 检测到 Ruby/Rails 应用程序
-----> 使用 Ruby 版本:ruby-1.9.3
-----> 使用 Bundler 版本 1.2.0 安装依赖项。 rc.2
但是我的应用程序正在中断,因为它需要 Ruby 1.9.3。错误如下:
TypeError:无法将数组
从 /app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/node.rb:214:in initialize 转换为字符串getaddrinfo'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/node.rb:214:in
按照这里的建议,我的路径开头有 bin
PATH => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
知道有什么问题吗?
更新:
Mongoid.yml
Heroku 推送输出:
服务器日志:
/app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/node.rb:214:in
getaddrinfo' /app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/node.rb:214:in
初始化'/app/vendor/bundle/ruby/1.9.1/gems/moped -1.2.0/lib/moped/cluster.rb:53:innew' /app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/cluster.rb:53:in
块初始化'/app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/cluster.rb:53 :在map' /app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/cluster.rb:53:in
初始化'/app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/session.rb:183 :在初始化new' /app/vendor/bundle/ruby/1.9.1/gems/moped-1.2.0/lib/moped/session.rb:183:in
'/app/vendor/bundle/ruby/1.9.1 /gems/mongoid-3.0.4/lib/mongoid/sessions/factory.rb:64:innew' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/sessions/factory.rb:64:in
create_session' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/sessions /factory.rb:43:indefault' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/sessions.rb:109:in
default' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/sessions.rb:378:in__session__' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/sessions.rb:213:in
mongo_session' /app/vendor/bundle /ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/sessions.rb: 157:在collection' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/contextual/mongo.rb:217:in
初始化'/app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/contextual.rb:47:innew' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/contextual.rb:47:in
create_context'/app/vendor/bundle/ruby/1.9.1/gems /mongoid-3.0.4/lib/mongoid/contextual.rb:30:incontext' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/contextual.rb:18:in
distinct' /app/app/controllers/my_controller.rb:14:inindex' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/implicit_render.rb:4:in
send_action' /app/vendor/bundle/ruby/1.9.1/gems /actionpack-3.2.3/lib/abstract_controller/base.rb:167:inprocess_action' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/rendering.rb:10:in
process_action' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/callbacks.rb:18 :inblock in process_action' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:436:in
run _647889395514353966__process_action_ 2178726499830545563 _callbacks' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in__run_callback' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in
_run_process_action_callbacks' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:inrun_callbacks' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/callbacks.rb:17:in
process_action' /app/vendor/bundle/ruby/1.9.1/gems /actionpack-3.2.3/lib/action_controller/metal/rescue.rb:29:inprocess_action' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:30:in
block in process_action' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/notifications .rb:123:inblock in instrument' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb:20:in
instrument' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/notifications.rb:123:ininstrument' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:29:in
process_action' /app/vendor/bundle/ruby /1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/params_wrapper.rb:205:inprocess_action' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/railties/controller_runtime.rb:18:in
process_action' /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.4.1/lib /new_relic/agent/instrumentation/rails3/action_controller.rb:34:inblock in process_action' /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.4.1/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:262:in
块在 perform_action_with_newrelic_trace' /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.4.1/lib/new_relic/agent/method_tracer.rb:242:intrace_execution_scoped' /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.4.1/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:257:in
perform_action_with_newrelic_trace' /app/vendor/bundle/ruby/1.9 .1/gems/newrelic_rpm-3.4.1/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:33:inprocess_action' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:121:in
process' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3 /lib/abstract_controller/rendering.rb:45:inprocess' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal.rb:203:in
dispatch' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/rack_delegation.rb:14:indispatch' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal.rb:246:in
块动作'/app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:73:incall' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:73:in
dispatch'/app/vendor/bundle/ruby/1.9.1 /gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:36:incall' /app/vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in
阻止通话' /app/vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:ineach' /app/vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in
call' /app/vendor/bundle/ruby/1.9.1 /gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:600:incall' /app/vendor/bundle/ruby/1.9.1/gems/omniauth-1.0.3/lib/omniauth/strategy.rb:168:in
call!/app/vendor/bundle/ruby/1.9.1/gems/omniauth-1.0.3/lib/omniauth/strategy.rb:148:incall' /app/vendor/bundle/ruby/1.9.1/gems/omniauth-1.0.3/lib/omniauth/builder.rb:42:in
call' /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm -3.4.1/lib/new_relic/rack/browser_monitoring.rb:12:incall' /app/vendor/bundle/ruby/1.9.1/gems/exceptional-2.0.32/lib/exceptional/integration/rack_rails.rb:13:in
call' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/rack/mongoid/middleware/identity_map .rb:33:inblock in call' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/mongoid/unit_of_work.rb:39:in
unit_of_work' /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.4/lib/rack/mongoid/middleware/identity_map.rb:33:incall' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/best_standards_support.rb:17:in
call' /app/vendor /bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/etag.rb:23:incall' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in
调用'/app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/head.rb:14:incall' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/params_parser.rb:21:in
call'/app/vendor/bundle/ruby/1.9.1 /gems/actionpack-3.2.3/lib/action_dispatch/middleware/flash.rb:242:incall' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in
context' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session /abstract/id.rb:200:incall' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/cookies.rb:338:in
call' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/query_cache.rb:64:incall' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in
call' /app/vendor /bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:28:inblock in call' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in
run _2458689492548881573_ call _1062142932397414625__callbacks' /app/vendor/bundle/ruby/1.9.1/gems/ activesupport-3.2.3/lib/active_support/callbacks.rb:405:in__run_callback' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in
_run_call_callbacks' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:inrun_callbacks' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:27:in
call' /app/vendor/bundle/ruby/1.9.1/gems /rack-1.4.1/lib/rack/sendfile.rb:102:incall' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/remote_ip.rb:31:in
call' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/debug_exceptions.rb :16:incall' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/show_exceptions.rb:56:in
call' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb:26:incall_app' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb:16:in
call' /app/vendor/bundle/ruby /1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/request_id.rb:22:incall' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in
call' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib /rack/runtime.rb:17:incall' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/cache/strategy/local_cache.rb:72:in
call' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:incall' /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/static.rb:62:in
调用'/app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:inforward' /app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in
fetch'/app/vendor/bundle/ruby/1.9.1 /gems/rack-cache-1.2/lib/rack/cache/context.rb:185:inlookup' /app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in
call!/app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:incall' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:479:in
call' /app/vendor/bundle/ruby/1.9.1/gems /railties-3.2.3/lib/rails/application.rb:220:incall' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in
method_missing' /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.4.1/lib/new_relic/rack/developer_mode.rb :24:incall' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:in
call' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/log_tailer.rb:14:incall' /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:80:in
block in pre_process' /app/vendor/bundle /ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:78:incatch' /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:78:in
pre_process' /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:53:inprocess' /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:38:in
receive_data' /app/vendor/bundle/ruby/1.9.1/gems /eventmachine-0.12.10/lib/eventmachine.rb:256:inrun_machine' /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in
run' /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/backends/base.rb:63 :instart' /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/server.rb:159:in
start' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:inrun' /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:265:in
start' /app/vendor/bundle/ruby/1.9 .1/gems/railties-3.2.3/lib/rails/commands/server.rb:70:instart' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:55:in
块在' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/ rails/commands.rb:50:intap' /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in
' 脚本/rails:6:inrequire' script/rails:6:in
'
mongoid - 如何在 Mongoid 中重命名 mongo 集合?
我有一个名为艺术家的收藏,我想将其重命名为 Artist_lookups。我该怎么做呢?
ruby-on-rails - How to add functionality to Mongoid::Document from a gem?
I want to create a gem which adds some functionality to my models. How to define a custom keyword for a Mongoid model? E.g.: