Questions tagged [mongoid4]

Version 4 of Mongoid, an Object-Document-Mapper (ODM) for MongoDB with Ruby. Use this tag for questions relating to this specific version.

Version 4 of Mongoid (an Object-Document-Mapper (ODM) for MongoDB)), which is compatible with Rails 4. For a deeper description of Mongoid, see the main Mongoid tag.

Primary tag:

Homepage

104 questions
0
votes
2 answers

Mongoid many to many relationship not working, what is wrong with my models?

I'm following the book Ruby and MongoDB Web Development, and and trying to follow the examples as much as possible, but for some reasons I'm not able to get it working. This is what I have so far, models: app/models/book.rb class Book include…
yeyo
  • 2,954
  • 2
  • 29
  • 40
0
votes
1 answer

Mongoid nested embedded document save ignores query

I'm having trouble saving the correct nested embedded document with mongoid. I've tried this in both v3.1.6 and v4.0.0 and the result is the same. The parent document is saved, but the nested document I modified ignores the changes, and instead…
Roberto
  • 1,944
  • 1
  • 30
  • 42
0
votes
1 answer

Mongoid how to set timeout

Mongoid can't connect to a remote MongoLab database from my machine, which I assume is due to network latency cause it works on the remote server. From MongoLab (http://docs.mongolab.com/connecting/#help). For network latency and security…
AJcodez
  • 31,780
  • 20
  • 84
  • 118
0
votes
2 answers

Rails route, show all elements on the same page

I need to show all my elements on the same page. In routes: namespace :nourishment do resources :diets do resources :nourishment_meals, :controller => 'meals' get 'nourishment_meals/show_all_meals' => 'meals#show_all_meals', as:…
0
votes
1 answer

Mongoid::Errors::InvalidScope with no aparent reason

I'm using mongoid-4.0.0.beta1 and following their docs to define a scope I get this error: /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta1/lib/mongoid/scopable.rb:306:in `check_scope_validity': …
aelesbao
  • 503
  • 4
  • 14
0
votes
1 answer

How to drop all databases located in mongoid.yml from rake task?

I want to drop all database sessions which located in mongoid.yml from rake task. I am using rails4 and mongoid4. Here is my mongoid.yml: development: sessions: default: database: cp1_dev hosts: - localhost:27017 …
zeitnot
  • 1,304
  • 12
  • 28
0
votes
2 answers

Mongoid 4 finding embedded documents by ID

I have a project that is my first serious dive into Mongoid. I saw a tip to use the following command: Parent.where('childrens._id' => Moped::BSON::ObjectId(params[:id])).first But this doesn't work. Error message was: NameError: uninitialized…
Mylan Connolly
  • 494
  • 1
  • 5
  • 15
0
votes
1 answer

Mongoid querying for parent by embedded children (using two values)

I have a Contact model, that has embedded Email models I am trying to query a Contact record, to find all the Contacts that have an Email address where the 'email_type' matches a string, and the 'unsubscribed' flag for that email is false MY best…
Jak Charlton
  • 231
  • 4
  • 9
0
votes
1 answer

Mongoid query for embeds_one

Following query is running in MongoDB console correctly, > db.venues.find({'location.region_id':ObjectId("533e67246d696e1279170000")}).count() 8 But when i write the same query in rails using mongoid its not showing anything, the query is as…
RubyOnRails
  • 235
  • 1
  • 15
0
votes
0 answers

Why does a Mongoid Array field contain hashes (["$each"=>"My value"]?)

I have an Array field in my Mongoid model. I am then pushing a few elements to this array. Do anyone know why my Array elements gets wrapped in hashes, all with the key "$each"? class Website include Mongoid::Document include…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
0
votes
1 answer

Mongoid 4 .or not working in complex query

I know Mongoid 4 is still in beta and maybe I've found a bug, but I'm having a hard time understanding why the first query works and the second one returns nothing: Product.or({sender_uid: params[:user_id]}, {receiver_uid:…
Graham
  • 463
  • 1
  • 5
  • 12
0
votes
2 answers

How to speed up performance by avoiding to query Mongoid multiple times?

I have approx. 10 million Article objects in a Mongoid database. The huge number of Article objects makes the queries quite time consuming to perform. As exemplified below, I am registering for each week (e.g. 700 days from now .. 7 days from now, 0…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
0
votes
2 answers

Mongoid: Query for objects where has_many associations have certain field values

I have a GiftCategory model: class GiftCategory include Mongoid::Document field :gifts_count, type: Integer has_many :gifts, :inverse_of => :gift_category end And I have a Gift model: class Gift include Mongoid::Document field…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
-1
votes
1 answer

Mongoid/Rails has_and_belongs_to_many returning true in loop - why?

I've got two models (product and category): class Product include Mongoid::Document include Mongoid::Timestamps field :name, type: String field :enabled, type: Boolean field :price, type:…
WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
1 2 3 4 5 6
7