ruby-on-rails - Mongo::Error::OperationFailure: $not need a regex or a document in rails mongoid
问题描述
Rails 应用程序具有 Moingoid 7.0.5
class Example
include Mongoid::Document
field :name, type: String
end
当我查询时Example.not(name: "xyz").count
,我收到此错误:
Mongo::Error::OperationFailure: $not 需要正则表达式或文档(2)(在 localhost:27017,现代重试,尝试 1)(在 localhost:27017,现代重试,尝试 1)
Mongoid 文档确实说我们也可以这样使用not
运算符。我确实得到了预期的结果Example.where(:name.ne => "xyz").count
。
配置中有什么导致这种情况的吗?
解决方案
已发布的文档表明它适用于哪个版本(左上角)。当前的 Mongoid 版本是 7.2,因此https://docs.mongodb.com/mongoid/current/tutorials/mongoid-queries/#logical-operations表明它适用于 7.2。您可以从下拉列表中选择您正在使用的版本。
not
您所询问的行为正在按照 Mongoid 7.1 的当前文档中描述的方式工作。正如您所发现的,以前版本的 Mongoid 不像当前描述的那样工作。
推荐阅读
- asp.net-core - .net Core **Never to Invoke**“next.Invoke after response has been sent to the client”那么如何实现符合良好实践的代码?
- google-cloud-platform - 在项目中查找与 GCP 服务帐号相关联的资源
- r - 如何在r中保持下三角形加对角线
- artifactory - 神器创造柯南频道
- swift - 使用 ArgumentParser 的 Swift 命令行应用程序
- amazon-web-services - 使用实例配置文件时如何在 AWS CLI 中设置配置文件名称
- java - 如何在 Graphics2D Java 中设置文本边界?
- google-assistant-sdk - 获取不成功的 webhook 调用:无法将 JSON 转换为 @assistant/conversation 中表的 ExecuteHttpResponse
- python - 为什么我的 python 程序没有启动 pygame?
- plugins - 如何构建一个 grafana 面板插件?