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
1
vote
1 answer

Why do I need reload objects before saving them in order for relations to update?

Not sure if this a Mongoid specific thing or if applies to the greater active record pattern. I have the following chunk of code, which works: submission.reload.profile submission.milestone = self.milestone submission.profile =…
Drew
  • 15,158
  • 17
  • 68
  • 77
1
vote
1 answer

Poor performance finding ids in mongodb using mongoid and rails 3

I'm getting poor performance doing a Model.find(array_of_ids) in mongodb using mongoid drive, and I don't understand why. Relevant code: ids = get_ids() #Get an array of 137 _ids for Topic model. Topic.find(ids) #Find all data, but take 4 seconds to…
1
vote
1 answer

Mongoid nested associations doesn't return Object

I have three models class User include Mongoid::Document include Mongoid::Timestamps has_many :conversation end class Conversation include Mongoid::Document include Mongoid::Timestamps has_many :users embeds_many :messages end class…
joe nayyar
  • 556
  • 1
  • 10
  • 18
1
vote
1 answer

how to order through a mongoid association

I want to order through a collections with values from an association. Example: I got multible associations for a Post like: Comments Ratings Attachements How can i order the posts through this associations like: order_by…
bulleric
  • 2,077
  • 6
  • 21
  • 36
1
vote
0 answers

Using the IPAddress Gem As a Custom Field in Mongoid

I'm trying to use IPAddress as a custom field for a Mongoid Document by monkey patching the serialization methods to the IPAddress module and I just can't seem to get it... class Computer include Mongoid::Document field :ip_address, type:…
1
vote
1 answer

Mongoid embedded documents Can't Convert String into Integer Error

I have this document call it Blog, Post, with embeds_many :posts, which by itself embeds_many :comments. It was giving me error "Can't convert String into Integer" when I try to save some blogs. Upon investigation I found embedded post documents…
Bashar Abdullah
  • 1,545
  • 1
  • 16
  • 27
1
vote
1 answer

rails mongoid url shortner

I've started creating a model based solution for creating short URLs, but I'm wondering if it wouldn't be better to do it in it's own collection (using mongoid) build an index for the tokens between models then search? Or if there's a gem that…
ere
  • 1,739
  • 3
  • 19
  • 41
1
vote
1 answer

MongoID many to many relation ship

I have two models with following relations, Class User has_and_belongs_to_many :notification_channels Class NotificationChannel has_and_belongs_to_many :users I am able to add notification channel for a user object in this…
Umair Ejaz
  • 273
  • 1
  • 2
  • 15
1
vote
2 answers

Calculate what page a model is on using kaminari and mongoid

I need to calculate what page a comment is on so I can create a direct link to it. I'm using kaminari pagination with monogid. On kaminari's wiki they have a solution on how to do it with activerecord but I'm not sure the best way to translate…
hadees
  • 1,754
  • 2
  • 25
  • 36
1
vote
1 answer

kaminari and Mongoid 3 page doesn't work as expected

Hi I am trying to use kaminari as a way to page my collection of 19K results however it doesn't seem to be doing what it is saying on the tin? I have 19293 documents: 1.9.3p194 :046 > Content.count => 19293 But when I try to get the first page I…
charleetm
  • 916
  • 1
  • 12
  • 26
1
vote
2 answers

How to order data by ONLY Hour:Minute format in MongoDB/Mongoid? (Without date!)

I'm using MongoDB and Mongoid in my project. I have some difficulties with ordering "Time" field data. As you know, eventhough you set a field type as Time inside your Mongoid Document, time data is stored as this format (note that I use +2 hours…
scaryguy
  • 7,720
  • 3
  • 36
  • 52
1
vote
2 answers

Rails and Mongoid and duplicate find queries

I have this really weird behaviour in my rails application. All find queries are run double. I've verified this by logging the queries both on the ap side and on the DB side. I've only tested it in development mode though. I've added logging to the…
deiga
  • 1,587
  • 1
  • 13
  • 32
1
vote
1 answer

Getting Mongoid to work with rails 3 along side active_record

in the installation guide to mongoid 3 it also explains how to disable active record, the problem is I am trying to integrate Mongoid in an existing project that extensively uses active_record with mysql, and I have no intention to change that. also…
Miki Bergin
  • 161
  • 11
1
vote
1 answer

Count frequency of an year

I'm trying to count the frequency of an year with map/reduce, here is the code map = %Q{ function(){ emit({}, { year: this.birthdate.getFullYear(), count: 1 }) } } reduce = %Q{ function(key, values){ var agg = { } …
Alexandre Bini
  • 127
  • 2
  • 12
1
vote
1 answer

How to find all and sort by count?

How to build a query that returns all entities sorted desc by count embedded post ids? Sample data: { "_id" : ObjectId( "5090f8061e7bf28095000012" ), "name" : "test", "post_ids" : [ ObjectId( "5090f8061e7bf28095000010" ) ], [ ObjectId(…
leon
  • 431
  • 7
  • 20