mongoid

setting mongoid hash field values

限于喜欢 提交于 2020-01-02 00:50:19
问题 I'm using Mongoid in a Rails project (both 4.0.x), and I've got a document with a hash field that stores some schema-less data. class Thing field :name, type: String field :mass, type: Integer field :info, type: Hash end With this setup, I can query for things, say, that have a key :endDate like so: Thing.where("info.endDate"=>{'$exists'=>true}) And that's all nice and handy. Using a hash field for this :info field is nice because what I want to store doesn't have a fixed schema and varies

Undefined method _s_path in form_for

别等时光非礼了梦想. 提交于 2020-01-01 19:32:14
问题 I know there are a bunch of questions on this. I've looked around, but I don't seem to be making the mistakes I've found answers to. The form for my workout resource, nested under users, is giving the error undefined method `workouts_path' for #<#<Class:0x007f88939c9e60>:0x007f8891527b20> That form goes: = form_for @workout do |f| ... = f.submit The Workouts Controller new action (where the error's being produced): def new @user = User.find(params[:user_id]) @workout = @user.workouts.new end

Increase MongoDB maximum number of connections

烂漫一生 提交于 2020-01-01 09:59:25
问题 I am getting some errors on MongoDB side, the error is complaining that it reached the max allowed connections. Wondering if there is anyway to increase the max number of allowed connections. 回答1: Check the MongoDB documentation: http://www.mongodb.org/ use this command line argument: --maxConns arg max number of simultaneous connections You might want to check this: http://blog.boxedice.com/2011/06/08/mongodb-connection-overhead/ 来源: https://stackoverflow.com/questions/7693989/increase

Mongoid and ActiveRecord generators

别说谁变了你拦得住时间么 提交于 2020-01-01 05:23:04
问题 I have both ActiveRecord (MySQL) and Mongoid in my Rails 3.1 application. Everything is fine, excepts all generators uses mongoid to generate models. This way, when i: rails g model user i receive mongoid-like model, but i need ActiveRecord structure and migrations. How can i switch back to AR? 回答1: Mongoid overrides the model generator, but you can switch it back. In config/application.rb you can either add a line if you've already got a block similar to this: config.generators do |g| g

Rails + Mongoid - Don't return nil values in JSON

有些话、适合烂在心里 提交于 2020-01-01 05:22:07
问题 I have a lot of optional fields in Mongoid, like: field :key, type: String field :element, type: String field :rect, type: Array If I return a json of this model with only one of them filled I get null values on all the other fields. How can I remove those fields? My model has nested attributes, which means null values can be on several levels. Clarifications: I need a way to remove null fields from the json representation of a model, including null fields in all nested attributes. Code

Collection ID length in MongoDB

梦想的初衷 提交于 2020-01-01 04:25:10
问题 i am new to mongodb and stack overflow. I want to know why on mongodb collection ID is of 24 hex characters? what is importance of that? 回答1: Why is the default _id a 24 character hex string? The default unique identifier generated as the primary key ( _id ) for a MongoDB document is an ObjectId. This is a 12 byte binary value which is often represented as a 24 character hex string, and one of the standard field types supported by the MongoDB BSON specification. The 12 bytes of an ObjectId

How to programmatically get the current database Mongoid is writing to?

不羁的心 提交于 2020-01-01 04:17:07
问题 I am talking to multiple databases using Mongoid.override_database("database_name") using Mongoid with rails. How do I find the current database programmatically? Mongoid docs on sessions: http://mongoid.org/en/moped/docs/driver.html define methods to override database but do not define a way to get the current database in use. 回答1: Got it! Mongoid.default_session.options[:database] 回答2: The new way to get this is Mongoid::Config.clients["default"]["database"] You can also just have a look at

Does anybody have any tips for managing polymorphic nested resources in Rails 3?

此生再无相见时 提交于 2020-01-01 03:10:52
问题 In config/routes.rb: resources :posts do resources :comments end resources :pictures do resources :comments end I would like to allow for more things to be commented on as well. I'm currently using mongoid (mongomapper isn't as compatible with Rails 3 yet as I would like), and comments are an embedded resource (mongoid can't yet handle polymorphic relational resources), which means that I do need the parent resource in order to find the comment. Are there any elegant ways to handle some of

DateTime with MongoDB/Mongoid and Rails 3 Not Populating

独自空忆成欢 提交于 2019-12-31 14:52:31
问题 Here is the code in my Model include Mongoid::Document include Mongoid::Timestamps field :message, :type => String field :send_at, :type => DateTime Here is the code for my form partial <%= f.label :send_at %><br /> <%= f.datetime_select :send_at %> But the date and time is never populated. I made sure that Mongo and Mongoid are up to date as well. Not sure if there's something I'm missing. [UPDATE LOG ENTRIES] Started POST "/notifis" for 127.0.0.1 at Mon Oct 18 05:48:05 -0400 2010 Processing

Can't get mongoid working with Rails 4

…衆ロ難τιáo~ 提交于 2019-12-31 12:59:05
问题 I followed the official tutorial. I have sqlite3 commented out in my Gemfile as well as the following lines: gem 'mongoid', '~> 4', github: 'mongoid/mongoid' gem 'bson_ext' However, I keep receiving the Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem "sqlite3" to your Gemfile. Reason seems to be that the database.yml still lists sqlite as the database. How am I supposed to get Rails to use the generated mongoid.yml? Replacing database.yml's contents with mongoid