问题标签 [moped]

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.

0 投票
1 回答
1417 浏览

ruby-on-rails - 使用 ruby​​ 保存/更新(轻便摩托车)BSON::Document

我尝试了很多方法来更新现有的 bson 文档,但它在我的 mongodb 中从未改变:

第一次尝试更新:

第二次尝试更新:

第三次尝试……

如您所见,以上都不适合我。我无法通过谷歌搜索找到任何其他建议。你知道如何更新我的文件吗?是否可以?

0 投票
0 回答
60 浏览

ruby-on-rails - 不使用模型的 Mongoid 迁移更新字段从字符串到时间戳

我想更新一个集合的字段,它实际上有一个日期的字符串表示,并将其更改为 ISODate。

我已经有了解决方案,但是效率低下:

我想在一次操作中更新它,而不是搜索和更新每条记录。

0 投票
1 回答
35 浏览

ruby-on-rails - 使用一个操作存储一组 mongoid 文档

使用Mopedgem 时,我可以存储一个哈希数组:

对于 mongoid 文档,它看起来像:

这意味着每个的插入操作。你知道保持单一操作方法的方法吗?也许像交易一样ActiveRecord

0 投票
1 回答
72 浏览

ruby - 如何在 ruby​​ mongoid 应用程序中测量轻便摩托车插入运行时间?

我目前正在编写一个轻便摩托车日志解析器,以监控轻便摩托车查询运行时。使用运行时参数的 QUERY 命令非常有用,但 INSERT 和 UPDATE 没有运行时参数。所有 INSERT 和 UPDATE 后跟一个包含运行时的getLastError命令。

以下是一些轻便摩托车日志的示例:

使用运行时查询

INSERT 没有运行时但使用 COMMAND

我很确定 COMMAND 运行时用于 getlasterror 调用,而不是用于我的 INSERT 调用。那么有没有办法为 INSERT 查询获取此运行时信息?

0 投票
0 回答
50 浏览

mongodb - 助力车 2.0.7 未定义方法“会话”

我不知道这里发生了什么。我升级到 MOPED 2.0.7,我得到了这个未定义的方法“会话”#

然后根据他们的文档here,我应该能够做到:

但是当我这样做时,我得到

有任何想法吗?

0 投票
1 回答
139 浏览

ruby-on-rails-3 - Resque 工作人员中的间歇性“Moped::Protocol::Command failed with error nil”错误

我正在使用 Rails 3.2、Mongoid 3.1.7、Moped 1.5.3 和 Resque 1.24.1

我的 Resque 工作人员反复收到“Moped::Protocol::Command failed with error nil”[1] 错误。

这个问题,以及Moped 回购中的这个问题让我认为这可能是由于 Resque 分叉,但它们都是关于旧版本的 Moped,而不是我正在使用的,而且我一直无法找到任何具体信息将 Resque 配置为与 Mongoid 很好地协同工作。

如何解决我的 Resque 工作人员中的错误?

[1] 完全错误: Exception: Moped::Errors::OperationFailure Error: The operation: #<Moped::Protocol::Command @length=58 @request_id=3 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="admin.$cmd" @skip=0 @limit=-1 @selector={:ismaster=>1} @fields=nil> failed with error nil /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:99:in `block in command' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:600:in `[]' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:600:in `block (3 levels) in flush' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:599:in `map' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:599:in `block (2 levels) in flush' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:150:in `ensure_connected' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:595:in `block in flush' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:610:in `logging' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:594:in `flush' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:583:in `process' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:92:in `command' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/node.rb:409:in `refresh' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:171:in `block in refresh' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:185:in `each' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:185:in `refresh' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:135:in `nodes' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cluster.rb:206:in `with_primary' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/session/context.rb:108:in `with_node' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cursor.rb:137:in `load_docs' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/cursor.rb:25:in `each' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/query.rb:76:in `each' /shared/bundle/ruby/2.2.0/gems/moped-1.5.3/lib/moped/query.rb:76:in `each' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual/mongo.rb:423:in `entries' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual/mongo.rb:423:in `check_existence' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual/mongo.rb:146:in `exists?' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/contextual.rb:19:in `exists?' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/uniqueness.rb:273:in `validate_root' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/uniqueness.rb:52:in `block in validate_each' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/queryable.rb:23:in `with_query' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations/uniqueness.rb:46:in `validate_each' /shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validator.rb:153:in `block in validate' /shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validator.rb:150:in `each' /shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validator.rb:150:in `validate' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:310:in `_callback_before_265' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:418:in `_run__123721054543109017__validate__3207805434451540367__callbacks' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:405:in `__run_callback' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:81:in `run_callbacks' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/callbacks.rb:130:in `run_callbacks' /shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations.rb:228:in `run_validations!' /shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:403:in `_run__123721054543109017__validation__3207805434451540367__callbacks' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:405:in `__run_callback' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks' /shared/bundle/ruby/2.2.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:81:in `run_callbacks' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/callbacks.rb:130:in `run_callbacks' /shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations/callbacks.rb:53:in `run_validations!' /shared/bundle/ruby/2.2.0/gems/activemodel-3.2.22/lib/active_model/validations.rb:195:in `valid?' /shared/bundle/ruby/2.2.0/gems/mongoid-3.1.7/lib/mongoid/validations.rb:84:in `valid?' /releases/20160315172839/app/performers/garmin_receive_push.rb:11:in `block in perform' /releases/20160315172839/app/performers/garmin_receive_push.rb:9:in `map' /releases/20160315172839/app/performers/garmin_receive_push.rb:9:in `perform'

0 投票
1 回答
632 浏览

ruby-on-rails - 如何强制轻便摩托车从延迟运行的 Mongo 辅助副本集成员读取

我有一个基于 ruby​​ on rails 的应用程序。目标是从一个 mongo 副本集成员中读取:

  1. secondary
  2. delayed by x seconds
  3. priority: 0
  4. 放置在单独的数据中心。

DETAILS:我有一个使用 mongo 副本集的生产集群正在运行。

以前,有人注意到,有时 Moped 从其他具有高延迟的辅助节点(远程存在于其他数据中心)而不是从所需的辅助节点读取。为了解决同样的问题,我们在远程辅助节点上添加了延迟。

现在我有一个使用 mongoid 的新分析应用程序。有没有一种方法可以强制使用 mongoid 或任何其他 gem 从 SPECIFIC 二级读取?即有没有办法覆盖 Mongoid / Moped / MongoDB 中的自动发现功能?请建议

0 投票
1 回答
922 浏览

ruby-on-rails - 助力车“无效的集合名称”

我最近在我的 rails 应用程序中将 mongoid 从 2.0 升级到了 3.0.0 版本。在执行保存对象(现有对象或新对象)的操作时,我Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command会说存在invalid collection name".

对象的 full_collection_name 返回foo_development.$cmdMongoid.default_session.collections返回空数组,但是当我通过 mongo 客户端访问数据库时,所有集合都已到位。

我的 mongoid.yml

development: sessions: default: database: foo_development hosts: - localhost:27017

0 投票
0 回答
16 浏览

mongodb - 如何在 mongoid/moped/mongodb 中启用异常

当我order_by的属性未知时,我的设置会静默失败。有没有办法改变这种行为,快速失败并出现错误/异常?

它使调试代码变得极其困难。

0 投票
1 回答
487 浏览

ruby-on-rails - Mongoid中的Mongo查询超时

如何在 Mongoid 中为我的 Mongo 查询设置超时?我知道 Mongo 支持cursor.maxTimeMS()但在 Mongoid 文档中找不到它。