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
5
votes
1 answer

Bundler could not find compatible versions for gem "activemodel"

Trying to install mongoid 3.1.6 in rails 4.1 Bundler could not find compatible versions for gem "activemodel": In Gemfile: mongoid (~> 3.1.6) ruby depends on activemodel (~> 3.2) ruby rails (= 4.1.0) ruby depends on activerecord (= 4.1.0)…
Mothirajha
  • 1,033
  • 1
  • 10
  • 18
5
votes
1 answer

How does Mongoid know the difference between string values and symbol values?

Consider this example: > x = User.first # or any persisted Mongoid::Document => # > x.set :foo, :bar => :bar > x.set :foo2, 'bar' => "bar" Note that "foo" and "foo2" are not declared in Ruby anywhere. THEN,…
Lawrence
  • 10,142
  • 5
  • 39
  • 51
5
votes
1 answer

Executing raw MongoDB queries in Rails controller

I have the follow raw mongo query that I want to execute directly in my Rails controller: db.user_places.update({place_id: destroy_model.id}, {$set: {place_id: keep_model.id}}, false, true) For sequel, I was using…
Huy
  • 10,806
  • 13
  • 55
  • 99
5
votes
1 answer

Mongoid - save and update_attribute does not persist

I am trying to update an attribute from a record in my Mongo collection, but the new value isn't being saved. a = GraphEngine::UserPlace.where(place_id:5000000701039).first a.place_id = 5000000257690 a.save! => true If I inspect a, the place_id…
Huy
  • 10,806
  • 13
  • 55
  • 99
5
votes
1 answer

Mongoid embeds_many / embedded_in relations with Formtastic in ActiveAdmin...?

Whew - lots of projects wrapped up in this one and I've done some (extensive) searching to no avail, so throwing up a flare to see if anyone else is working with a similar stack and has a solution. I'm using a Mongoid-enabled fork of ActiveAdmin to…
nlh
  • 1,055
  • 1
  • 10
  • 15
5
votes
2 answers

How find all overlapping circles from radius of central circle?

How to do an intersection or overlap query in mongo shell - what circles overlap my search region? Within relate only to the center position but doesn't include radius of the other circles in searched scope. Mongo: # My bad conception: var search =…
roza
  • 585
  • 1
  • 9
  • 30
5
votes
1 answer

MongoDB error with Mongoid, Heroku, Device, MongoHQ and Rails

I'm working on a simple app that is currently deployed to heroku now - it is using mongoid, device and can create user login very easily in localhost, but not in production at heroku. You can try to create an account, and it gives an error after…
Sayanee
  • 4,957
  • 4
  • 29
  • 35
4
votes
0 answers

Mongoid with rails, how to do order_by on association count?

I have two models say: user and post user.rb has_many :posts And post.rb belongs_to :user, :index => true I need to show users order_by number of posts added by them. One way to do this is: User.all.sort{|a,b| b.posts.count <=> a.posts.count} But…
Minu
  • 101
  • 5
4
votes
3 answers

Mongoid fields and subsequently added localization

Is there something to consider when I am adding localization later on? from class Articles field :title, type: String to class Articles field :title, type: String, localize: true I have content on my Articles model and wanna add…
Jan
  • 12,992
  • 9
  • 53
  • 89
4
votes
1 answer

Mongoid: Referencing Same Model More Than Once Through has_many

I'd like to be able to reference a model (a has_many relationship) more than once in the same model. For example, given the following models: class MyModel include Mongoid::Document field :name, type: String has_many :main_efforts,…
senfo
  • 28,488
  • 15
  • 76
  • 106
4
votes
2 answers

Retrieve an embedded document using Mongoid

I have a Mongoid document called Equipment which can embed multiple Question documents. Here are the document schemas: class Equipment include Mongoid::Document include Mongoid::Timestamps field :description field :modelNumber field…
Rich Blumer
  • 960
  • 1
  • 15
  • 26
4
votes
1 answer

Mongo combine and or in a single query

I am trying to figure out the best way to query mongo. I am using Mongoid and latest mongo version What I want to do is query like this user_id => [array of ids] and user_type => "some_type" OR user_id => [array of ids] and user_type =>…
KensoDev
  • 3,285
  • 21
  • 38
4
votes
4 answers

Clear db with mongoid3

I like to perform a set up before each time I run a unit test and clear my mongo db, how do I do it with mongoid? I found some links about it while googling but nothing seemed to work.
Chen Kinnrot
  • 20,609
  • 17
  • 79
  • 141
4
votes
1 answer

Mongoid 3 Complex Query with ANDs and ORs

I have a Rails 3.2 Blog app which shows posts to users based on their company and their region. I also want to to show posts where the user is the post's author, even if it was created for another company or region (the Post object has a region and…
tagCincy
  • 1,589
  • 10
  • 20
3
votes
6 answers

Rails Mongoid `pluck` equivalent?

In my Rails app I am using MongoID with a Elasticsearch river for text search. For @devices_with_config = ConfigTextSearch.search params[:device_id] I want to extract just the device_id fields for the matching records in the query. In mongoID…
dman
  • 10,406
  • 18
  • 102
  • 201
1
2
3
14 15