Questions tagged [mongoid3]

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

Version 3 of Mongoid (an Object-Document-Mapper (ODM) for MongoDB). For a deeper description of Mongoid, see the main Mongoid tag.

Primary tag:

211 questions
2
votes
1 answer

mongoid where with has_many relation

I have 3 models City.rb has_many :places Place.rb has_many :reviews, as: :reviewable And Reviews which have an attribute state which I would like to be able to check. Review.rb belongs_to :reviewable, polymorphic: true state_machine :initial…
ere
  • 1,739
  • 3
  • 19
  • 41
1
vote
0 answers

Push and pull elements to an array in one query with mongodb

With Mongoid, I'm trying to do : models.update_all({ '$pullAll' => { category_ids: removed_category_ids }, '$addToSet' => { category_ids: { '$each' => added_category_ids } } }) I have this error message : Mongo::Error::OperationFailure: …
Dougui
  • 7,142
  • 7
  • 52
  • 87
1
vote
2 answers

How to update an attribute without touch

Is there an option to not touch the updated_at attribute when i update an attribute in mongoid ? Something similar to model.save(validate: false) or, better, model.update_attribute(:attribute, 'value') ?
JoJoS
  • 1,971
  • 2
  • 13
  • 15
1
vote
1 answer

Convert rails query to mongoid query

I have a existing rails query but it doesn't work with mongoid .I need to convert so that it works with mongoid Here is the query scope :between, -> (sender_id,recipient_id) do where("(conversations.sender_id = ? AND conversations.recipient_id…
user6551529
  • 121
  • 14
1
vote
0 answers

Can 'mongoid-minitest' gem be used for writing controller test cases?

I am using 'mongoid-minitest' for writing test suite for my app I have successfully added test cases for models using this gem. I tried adding controller test cases. users_controller_test.rb require 'test_helper' describe UsersController do …
Minu
  • 101
  • 5
1
vote
1 answer

Undefined method `reset_counters' for Mongoid 3.1.6

I just updated my mongoid to version 3.1.6, so that I could use the reset_counters method to keep track of my model relations. But just as I did before the gem update I still get this error: undefined method `reset_counters' for…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
1
vote
2 answers

MongoId Embedded Document With Reference

I have the following case where I have a document that I need to embed in some documents, but for traceability (e.g need to know the amount of people who is subscribed to each type) I need it to be stored as a different document. So when I try to…
sescob27
  • 647
  • 1
  • 8
  • 17
1
vote
0 answers

Mongoid.override_database in Sidekiq and simultaneous Rails requests

I'm just wandering when can I safely use Mongoid.override_database. If I use it inside Sidekiq worker is DB going to be changed only for the worked which has called the override_database method? How about using it in standard Rails controller? Is…
xx77aBs
  • 4,678
  • 9
  • 53
  • 77
1
vote
0 answers

Create Tag Cloud with Mongoid Taggable Gem

I want to create a tag cloud just like you can with the acts-as-taggable-on gem, this is an example from the acts-as-taggable-on gem readme: <% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %> <%= link_to tag.name, { :action =>…
Dan Mitchell
  • 844
  • 2
  • 15
  • 34
1
vote
1 answer

two methods for after_add callback on mongoid relations

How can we have two methods for after_add callback on mongoid relations. Both the methods need to do different things? has_and_belongs_to_many :posts, after_add: method1, after_add: method2
Asma
  • 23
  • 3
1
vote
1 answer

Process Hashes in Document Collections Mongoid

I have a web application where I'm storing the type of users as a hash field. and i have many collections. what would be the best way to process that hash field. class Community include Mongoid::Document class UserRoles Admin = :a …
Ronak Jain
  • 1,723
  • 2
  • 24
  • 35
1
vote
2 answers

adding allowDiskUse parameter to db.collection.aggregate() query using Mongoid

I recently updated mongodb from 2.4 to 2.6, and the new memory limit in aggregate() is causing my aggregation to fail with the following error: Moped::Errors::OperationFailure: The operation: #
diego
  • 123
  • 2
  • 14
1
vote
2 answers

Mongoid Moped query not returning the same as the MongoDB shell

Creating a query using Mongoid 3.1.5 and MongoDB 2.4.9 I get different results from the Mongoid/Moped query that I do from the equivalent MongoDB query. Update added Mongoid query The query in its long for is: return Video.order_by(release_date:…
pferrel
  • 5,673
  • 5
  • 30
  • 41
1
vote
1 answer

How to get documents sorted via distance with "within_spherical_circle" in mongoid

I am working on a small module which deals with the nearby documents for given spherical lookup. While working with mongoid3 I used the following to receive documents with given latitude, longitude and spherical distance to lookup the documents.…
r3bo0t
  • 462
  • 4
  • 11
1
vote
2 answers

How to nest .or() and .and() conditions in Mongoid

I have a 'search' function where I want to pass in an arbitrary 'filter' condition and have matches returned The following matches any name/email where the filter string is a match: @people = Person.all @people = @people.or( {'name.first_name'…
Jak Charlton
  • 231
  • 4
  • 9