mongoid

In MongoDB, if an index is on 3 fields, we can use that index when querying on 2 fields? (wildcard on the 3rd field)

我们两清 提交于 2019-12-20 03:41:13
问题 If there is an index on page_type, our_id, date and when querying, db.analytics.find({page_type: 'ingredients', ga_date: {$gte : new Date('Wed Sep 08 2010 12:00:00 GMT-0800')}}) db.analytics.find({page_type: 'ingredients', ga_date: {$gte : new Date('Wed Sep 08 2010 12:00:00 GMT-0800')}}).explain() if our_id is omitted, or date is omitted, it can still use the index, with something like the following in the explain() output: "our_id" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ], even

I am using rails cast omniauth and i get this error

人盡茶涼 提交于 2019-12-20 03:19:53
问题 I am using Mongodb as database in rails and i got error when using /auth/linkedin/callback NoMethodError in AuthenticationsController#create undefined method []' for nil:NilClass Rails.root: /home/prem/Music/heronhrm Application Trace | Framework Trace | Full Trace app/models/user.rb:57:in apply_omniauth' app/controllers/authentications_controller.rb:19:in `create' Also when i remove self.email = omniauth['user_info']['email'] if email.blank? from usermodel then the validation errors arises

MongoDB won't connect to MongoHQ using Mongoid

拜拜、爱过 提交于 2019-12-20 02:32:36
问题 I've just started a brand new rails project and the first task I'm trying to complete is creating an object and having it save within my database. I went through the automated way of generating an object, in this case a URL object as follows: rails generate scaffold Url domain:string I've also tested out two separate mongoid.yml configuration settings. The first is as follows: development: sessions: default: # Defines the name of the default database that Mongoid can connect to. # (required).

Strong Params, Nested Attributes and Mongoid don't seem to work because of *_attributes suffix in form?

ε祈祈猫儿з 提交于 2019-12-19 10:29:18
问题 I'm trying to embed property groups on my main Person model to help keep my code organised but Rails 4's Strong Params is getting in the way. The Scenario I have a Person model and a PersonName model like so: class Person include Mongoid::Document embeds_one :name, class_name: 'PersonName' accepts_nested_attributes_for :name end class PersonName include Mongoid::Document embedded_in :person, inverse_of: :name # fields here end I then use the fields_for helper in my form to nest the PersonName

Undefined Method Error when creating delayed_job workers with script/delay_job

余生颓废 提交于 2019-12-19 10:28:15
问题 Having a bit of a problem running multiple workers. When creating workers with rake jobs:work jobs run without and problem, even when invoking it multiple times, but when creating workers with ruby script/delayed_job -n 5 start all jobs fail with undefined method on Syck::DomainType . I've searched quite a bit, but can't seem to find the solution for this. I am running DelayedJob on the Mongoid backend. Gem versions: rake 0.9.2 rails 3.0.6 delayedjob 2.1.4 delayedjob_mongoid 1.0.2 Has anyone

How to get print output for debugging map/reduce in Mongoid?

好久不见. 提交于 2019-12-19 06:59:06
问题 I'm writing a map/reduce operation with Mongoid 3.0. I'm trying to use the print statement to debug the JS functions. This is a troubleshooting suggestion from the MongoDB docs, e.g.: reduce = %Q{ function(user_id, timestamps) { var max = 0; timestamps.forEach(function(t) { var diff = t.started_at - t.attempted_at; if (diff > max) { max = diff; } }); print(user_id + ', ' + max); return max; }; } MyCollection.all.map_reduce(map, reduce).to_a Unfortunately the output from the print statement

How-to: User has fans

旧时模样 提交于 2019-12-19 03:12:38
问题 I need users to be able to become fans of other users. How should I design/set this up? I need to be able to view details of user fans. For example. I have user: Foo. Foo has 3 fans. I'd like to be able to find the names of Foo's fans. As such: foo = User.first foo.name (returns 'Foo') foo.fans.first.user.name (should return 'bar', since 'bar' is a fan of 'foo') This is how I have it set up at the moment: User model: embeds_many :fans references_many :fans Fan model: embedded_in :user,

Rails Mongoid fails to authenticate - failed with error 13: “not authorized for query on my_db.my_collection”

亡梦爱人 提交于 2019-12-18 19:07:18
问题 This issue was said to be resolved the latest version of Moped but still happens to me. I have a rails 4.2 app with Mongoid, created a user for a MongoDB DB with readWrite and dbOwner roles, and set auth=true in the mong.conf file. I can perform any actions on the DB with that user credentials using the Mongo shell or a simple Java application using their Mongo driver. However, when trying to authenticate with Mongoid I always get this error: failed with error 13: "not authorized for query on

Ruby model output id as object oid

坚强是说给别人听的谎言 提交于 2019-12-18 12:31:08
问题 My ruby model, like so: class User include Mongoid::Document field :first_name, type: String field :birthdate, type: Date validates :first_name, :birthdate, :presence => true end outputs an object like so: { _id: { $oid: "522884c6c4b4ae5c76000001" }, birthdate: null, first_name: null, } My backbone project has no idea how to handle _id.$oid. I found this article and code: https://github.com/rails-api/active_model_serializers/pull/355/files module Moped module BSON class ObjectId alias :to

Ruby model output id as object oid

穿精又带淫゛_ 提交于 2019-12-18 12:31:03
问题 My ruby model, like so: class User include Mongoid::Document field :first_name, type: String field :birthdate, type: Date validates :first_name, :birthdate, :presence => true end outputs an object like so: { _id: { $oid: "522884c6c4b4ae5c76000001" }, birthdate: null, first_name: null, } My backbone project has no idea how to handle _id.$oid. I found this article and code: https://github.com/rails-api/active_model_serializers/pull/355/files module Moped module BSON class ObjectId alias :to