mongoid

MongoDB and Mongoid in production

雨燕双飞 提交于 2019-12-31 10:42:18
问题 I am deploying my first little app with MongoDB and Mongoid as a driver. What is the right secure way to use MongoDB in production? I mean in the development I have just started mongod and that's it - no username or password needed and that looks unsecure. Also Mongoid sets default configurations production: host: <%= ENV['MONGOID_HOST'] %> port: <%= ENV['MONGOID_PORT'] %> username: <%= ENV['MONGOID_USERNAME'] %> password: <%= ENV['MONGOID_PASSWORD'] %> database: <%= ENV['MONGOID_DATABASE'] %

How can I use Mongoid and ActiveRecord in parallel in Rails 3?

不想你离开。 提交于 2019-12-31 09:17:09
问题 I'm using rails 3, and began my application with ActiveRecord. Now, I have many models, and the relations are starting to get complicated, and some could be more simply expressed with a Document-Oriented structure, so I'd like to try migrating to MongoDB and use Mongoid. I've always heard that you didn't have to eitheer use all MongoDB or nothing, but that you could use the two in parallel while migrating. I don't see how to go about this from the docs though. For example, I have: class User

Use LIKE/regex with variable in mongoid

和自甴很熟 提交于 2019-12-31 09:16:11
问题 I'm trying to find all documents whose text contains the word test. The below works fine: @tweets = Tweet.any_of({ :text => /.*test.*/ }) However, I want to be able to search for a user supplied string. I thought the below would work but it doesn't: searchterm = (params[:searchlogparams][:searchterm]) @tweets = Tweet.any_of({ :text => "/.*"+searchterm+".*/" }) I've tried everything I could think of, anyone know what I could do to make this work. Thanks in advance. 回答1: searchterm = (params[

running rails 3.2 / mongoid app on heroku fails

半腔热情 提交于 2019-12-31 05:48:07
问题 I'd like to now if anybody could help me with my heroku deployement. I've set up my Rails 3.2 app with the following Gemfile source 'https://rubygems.org' gem 'rails', '3.2.0' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3-ruby', :require => 'sqlite3' gem 'mongoid' gem 'bson_ext' gem 'mongoid_slug' gem 'heroku' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3'

Mongoid store_in produces random results

我的梦境 提交于 2019-12-30 10:14:53
问题 I am using Rails 3.2.2 with mongoid 2.4.6. In order to keep my collections small I am storing child objects to a base class in sepparate collections using the "store_in" statement. My code looks like this: class BaseClass include Mongoid::Document end class ChildClass1 < BaseClass store_in :child_1 end class ChildClass2 < BaseClass store_in :child_2 end It appears that the objects get randomly stored in or or the other child collection. An object of type Child1 sometimes gets stored in

Mongoid / Mongodb and querying embedded documents

夙愿已清 提交于 2019-12-29 18:35:26
问题 I have Author and Book models. An Author has many embedded Books . Can I query the embedded Books , or do I have to fetch Authors first to get Books ? 回答1: You can query embedded documents, just qualify the name. Now, this will return all Authors that have books that match your query. If Author is defined as having many :books (and book is an embedded::document) @authors_with_sewid = Author.where("books.name" => "sewid").all You'd then need to iterate over the authors and extract the books.

MongoDB Aggregation: Compute Running Totals from sum of previous rows

可紊 提交于 2019-12-29 04:03:45
问题 Sample Documents: { _id: ObjectId('4f442120eb03305789000000'), time: ISODate("2013-10-10T20:55:36Z"), value:1 }, { _id: ObjectId('4f442120eb03305789000001'), time: ISODate("2013-10-10T28:43:16Z"), value:2 }, { _id: ObjectId('4f442120eb03305789000002'), time: ISODate("2013-10-11T27:12:66Z"), value:3 }, { _id: ObjectId('4f442120eb03305789000003'), time: ISODate("2013-10-11T10:15:38Z"), value:4 }, { _id: ObjectId('4f442120eb03305789000004'), time: ISODate("2013-10-12T26:15:38Z"), value:5 } It's

MongoDB Aggregation: Compute Running Totals from sum of previous rows

雨燕双飞 提交于 2019-12-29 04:03:22
问题 Sample Documents: { _id: ObjectId('4f442120eb03305789000000'), time: ISODate("2013-10-10T20:55:36Z"), value:1 }, { _id: ObjectId('4f442120eb03305789000001'), time: ISODate("2013-10-10T28:43:16Z"), value:2 }, { _id: ObjectId('4f442120eb03305789000002'), time: ISODate("2013-10-11T27:12:66Z"), value:3 }, { _id: ObjectId('4f442120eb03305789000003'), time: ISODate("2013-10-11T10:15:38Z"), value:4 }, { _id: ObjectId('4f442120eb03305789000004'), time: ISODate("2013-10-12T26:15:38Z"), value:5 } It's

Mongoid order by length of array

a 夏天 提交于 2019-12-25 07:14:15
问题 How to sort the Mongoid model by the length of the array which is a field inside the model. 回答1: Document says that you can't orderby using size. Try adding a new column containing the value of size and sort it which will work as order by. 回答2: Mongo documentation says: You cannot use $size to find a range of sizes (for example: arrays with more than 1 element). If you need to query for a range, create an extra size field that you increment when you add elements. Indexes cannot be used for

Rails mongoid dynamic fields - no method error

时光怂恿深爱的人放手 提交于 2019-12-25 03:37:22
问题 ENV: Rails-3.2.12 Ruby-1.9.3 Mongoid-3.1.1 I have model: class Item include Mongoid::Document field :name, type: String field :type, type: String end but if I try to add dynamic field in view, lets say "color", i get an undefined method error. allow_dynamic_fields: true is enabled in the config file. _form.html.erb: <%= form_for(@item) do |f| %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> <div class="field"> <%= f.label :type %><br /> <%= f.text_field :type