标签: mongoid

ActiveRecord :: ConnectionNotEstablished(ActiveRecord :: ConnectionNotEstablished)

我有一个与mongodb一起使用的Rails应用程序.我想将它部署到Heroku,但得到错误:

       Using sass-rails (3.2.5)
       Installing sqlite3 (1.3.5) with native extensions Unfortunately, a fatal error has occurred.
Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues
so that we can fix it. Thanks!
       /usr/local/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions':
 ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
Run Code Online (Sandbox Code Playgroud)

好吧,我在我的Gemfile中评论了sqlite-gem:

# gem 'sqlite3'
Run Code Online (Sandbox Code Playgroud)

现在它在heroku上正确部署,但我在使用应用程序时遇到错误:

[2012-03-21 12:53:46] INFO  WEBrick::HTTPServer#start: pid=9896 port=3000
MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails heroku mongodb mongoid

1
推荐指数
1
解决办法
4028
查看次数

将 geoNear 与 Rails / Mongoid 结合使用

我在使用 MongoDB / Rails 查询地理空间索引时遇到问题。我正在使用这个 gem - https://github.com/kristianmandrup/mongoid_geospatial

这是我相当基本的模型:

class Company
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Geospatial

  field :name, type: String

  field :location, type: Array, spatial: true

  spatial_index :location

  validates :location, location: true
end
Run Code Online (Sandbox Code Playgroud)

然后,在我的控制器中,我有这个

    #@vendors = Vendor.where(:location.near => {:point => [-2.1294761000000335,57.0507625], :max => 5})
Run Code Online (Sandbox Code Playgroud)

然而,这并没有返回预期的结果(即,它返回来自各地的东西,而不仅仅是靠近特定的经度/纬度)

另外,我将如何对此进行 geoNear 呢?
这样我就可以得到每个结果到中心点的距离?

注意 写完这个问题后,我看到 gem 已更新,但我不确定是否有更好的替代方案..?

ruby-on-rails geospatial mongodb mongoid ruby-on-rails-3

1
推荐指数
1
解决办法
2473
查看次数

如何在mongoid中保存嵌入式类?

我正在使用带有mongoid 2的Rails 3.我有一个mongoid类论坛,它嵌入了很多主题.主题embeds_many forumposts

当我试图保存一个forumpost在我的控制器中执行以下操作时...

@forum = Forum.find(params[:forum_id])
@forum.topics.find(params[:topic_id]).forumposts.build(:topic_id => params[:forumpost][:topic_id], :content => params[:forumpost][:content], :user_id => current_user.id,:posted_at => Time.now, :created_at => Time.now, :updated_at => Time.now)
if @forum.save
Run Code Online (Sandbox Code Playgroud)

救了我得...

未定义的方法`每个'为2012-11-14 23:15:39 UTC:时间

为什么我会收到这个错误?

我的forumpost课程如下......

class Forumpost
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia

  field :content, type: String
  field :topic_id, type: String
  field :user_id, type: String
  field :posted_at, type: DateTime

    attr_accessible :content, :topic_id, :user_id, :posted_at, :created_at, :updated_at

  validates :content, presence: true
  validates :topic_id, presence: true
  validates :user_id, presence: true

    belongs_to :topic
    belongs_to :user …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails mongodb mongoid ruby-on-rails-3

1
推荐指数
1
解决办法
2633
查看次数

MongoDB map/reduce"NoMethodError:未定义的方法`map_reduce'用于#<Moped :: Collection"

我试图通过ruby控制台在集合上使用map_reduce,但是我得到了"NoMethodError:未定义的方法`map_reduce'#

results = Thing.collection.map_reduce(map, reduce, out: "vr")
Run Code Online (Sandbox Code Playgroud)

mongodb mongoid

1
推荐指数
1
解决办法
1161
查看次数

求和 Mongoid BigDecimal

Mongoid 3 文档显示您可以使用以下内容进行简单的求和: Band.sum(:likes)

我有以下简单模型:

class Project
  ...
  has_many :subprojects
  ...
end

class Subproject
  ...
  field :subtotal, :type => BigDecimal, :default => 0
  ...
end
Run Code Online (Sandbox Code Playgroud)

我如何总结subtotal每个Project

例如,我试过

Project.first.subprojects.sum(:subtotal) 它返回 0。

Project.first.subprojects.first.subtotal返回#<BigDecimal:7fcb0d77b958,'0.11054E3',18(18)>

有什么建议?

mongoid ruby-on-rails-3

1
推荐指数
1
解决办法
865
查看次数

Mongoid :数组包含元素或为空

如果字符串在数组中或数组为空,我想发出一个请求,该请求从我的集合中返回元素。我尝试了以下方法:

Collection.all_of(or: [{ assets: my_asset }, { assets: [] } ])
Run Code Online (Sandbox Code Playgroud)

但这不起作用。

这有效但不适用于空数组:

Collection.where(assets: my_asset)
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails mongodb mongoid mongodb-query

1
推荐指数
1
解决办法
700
查看次数

范围不适用于 Mongoid(未定义方法“to_criteria”)

ReleaseSchedule.next_release我在其他控制器中调用

并得到以下错误

NoMethodError (undefined method `to_criteria' for #<ReleaseSchedule:0x007f9cfafbfe70>):
  app/controllers/weekly_query_controller.rb:15:in `next_release'
Run Code Online (Sandbox Code Playgroud)

发布_schedule.rb

class ReleaseSchedule
  scope :next_release, ->(){ ReleaseSchedule.where(:release_date.gte => Time.now).without(:_id, :created_at, :updated_at).first }
end
Run Code Online (Sandbox Code Playgroud)

mongoid ruby-on-rails-4 mongoid4

1
推荐指数
1
解决办法
1610
查看次数

MongoID Like 对嵌入式模型的查询

我有用户模型embeds_one :profile和 Profile 模型有名称。我需要对配置文件名称运行LIKE 查询。我按照这里的建议尝试了以下

User.where("profile.name" => "/.*Senthil.*/")
Run Code Online (Sandbox Code Playgroud)

但上述解决方案不起作用。我尝试了很多股票溢出答案,但没有运气。任何帮助将不胜感激。

截图:我很确定,有匹配记录。

在此处输入图片说明

ruby-on-rails mongodb mongoid ruby-on-rails-4

1
推荐指数
1
解决办法
1292
查看次数

在 Mongoid 中使用带有选项allowDiskUse的聚合

问题:

allowDiskUse:true在 MongoDB 查询中使用排序时,我的内存超出了限制,并告诉我在查询中使用选项。但在 Rails mongoid 中,聚合函数没有传递任何选项。

我收到的错误:

Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in. (16819)
Run Code Online (Sandbox Code Playgroud)

我的代码/查询:

result = ModelName.collection.aggregate([
      {"$sort" => {
          "created_at" => 1
      }}
    ], {'allowDiskUse' => true})
Run Code Online (Sandbox Code Playgroud)

我的目标:

allowDiskUse在 mongoid 查询中使用选项,以便我可以按创建时间获取排序数据,但我猜 mongoid 不支持它,所以我需要一些替代方案。关于我应该做什么有什么建议吗?

ruby-on-rails mongoid

1
推荐指数
1
解决办法
1378
查看次数

Rails、Mongoid、使用环境变量进行数据库配置会抛出 NoMethodError

我正在尝试将使用 mongoid 的 Rails 应用程序部署到我的远程生产服务器。

在我的中mongoid.yml我添加了这个:

hosts:
    - <%= ENV['MONGOSERVER_PORT_27017_TCP_ADDR'] %>:27017
Run Code Online (Sandbox Code Playgroud)

当我启动 Capistrano 时,它会抛出以下错误:

SSHKit::Command::Failed: rake exit status: 1
rake stdout: rake aborted!
NoMethodError: undefined method `split' for :"27017":Symbol
Run Code Online (Sandbox Code Playgroud)

添加下划线会导致此错误发生吗?

ruby capistrano ruby-on-rails bundler mongoid

1
推荐指数
1
解决办法
716
查看次数