Questions tagged [mongoid]

Mongoid is the official Ruby Object-Document-Mapper (ODM) for MongoDB.

Mongoid (pronounced mann-goyd) is an Object-Document-Mapper (ODM) for MongoDB written in Ruby. Mongoid as of version 5 is under the control and guidance of MongoDB as the official Ruby ODM.

The philosophy of Mongoid is to provide a familiar API to Ruby developers who have been using Active Record or Data Mapper, while leveraging the power of MongoDB's schema-less and performant document-based design, dynamic queries, and atomic modifier operations.

4728 questions
2
votes
1 answer

is "collection" a reserved word in rails 3.2, simple_form or in mongoid/mongodb?

I am having problems with the model "Collection". I'm using mongoid with mongodb and rails 3.2. I have the problem when I try create a nested resource from collection with a select with simple_form sth like: <%= f.input :collection_id, :collection…
hyperrjas
  • 10,666
  • 25
  • 99
  • 198
2
votes
1 answer

MongoDB shell breaks the syntax for long queries

I have a query that takes 3 lines. In the mongo shell, I can type it out so it is on one line, but if I paste it, it goes to 3 lines, and that breaks the syntax. The same thing happens when I am writing a JavaScript Shell script to execute some…
Genadinik
  • 18,153
  • 63
  • 185
  • 284
2
votes
1 answer

Mongoid - field with array of references

Im newbee in mongoid and I have two basic (I think) questions. Whats best way to store array of references in Mongoid. Here is a short example what I need (simple voting): { "_id" : ObjectId("postid"), "title": "Dummy title", "text": "Dummy…
enRai
  • 671
  • 6
  • 12
2
votes
1 answer

Calling parent constructor when initialize overridden by included module

I have a class hierarchy as follows: class Tree def initialize(id, value) @id, @value = id, value end end class Entity < Tree include Mongoid::Document def initialize(id, value) # Do some stuff... super(id, value) …
user2398029
  • 6,699
  • 8
  • 48
  • 80
2
votes
1 answer

Mongodb - how can I query by date range?

I am new to Mongo. I am trying to query for a date range. The user model has this field: field :confirmed_at, :type => Time could someone help me write a query to get users who confirmed their account for some time range? Here is…
GeekedOut
  • 16,905
  • 37
  • 107
  • 185
2
votes
1 answer

Mongoid- accepts_nested_attributes_for not saving

I have a one to many relationship between EnquiryForm and UniversityFeeInstallment EnquiryForm has_many UniversityFeeInstallment. Following is the params I receive from…
Pravin
  • 6,592
  • 4
  • 42
  • 51
2
votes
1 answer

mongoid include soft deleted document

Mongoid supports soft deletion with include Mongoid::Paranoia Lets suppose i have soft deleted a document from one of the collection. Now I need a query that includes a soft deleted document from that collection. How can I do that? Do I need to…
Gagan
  • 4,278
  • 7
  • 46
  • 71
2
votes
1 answer

How can I set "allow_dynamic_fields" on a per collection basis in Mongoid?

Mongoid only seems to have an app wide Mongoid.allow_dynamic_fields setting. But I want every collection to decide whether it wants dynamic fields or not. How can I do that?
Coffee Bite
  • 4,956
  • 5
  • 33
  • 38
2
votes
2 answers

Trying to connect to a mongodb instance on ec2 with mongoid as orm in rails

basically I have a mongodb instance running and working on ec2. On the side I have a rails 3.2 app with mongoid as orm working on local. What I want to do next is try to connect my rails app to the mongodb instance using mongoid. Also, intending to…
John Lee
  • 1,241
  • 2
  • 16
  • 29
2
votes
2 answers

Why do I get an error installing bson_ext?

When I execute the following command in the Rails project folder: gem install bson_ext I get the this error: #result Building native extensions. This could take a while... ERROR: Error installing bson_ext: ERROR: Failed to build gem native…
aash
  • 1,323
  • 1
  • 14
  • 22
2
votes
2 answers

How would I grab only articles with comments that were created 20 minutes ago?

Using mongodb and mongoid. How would one grab all articles. Only articles with comments created 20 minutes ago? class Article include Mongoid::Document has_many :comments end class Comment include Mongoid::Document belongs_to…
Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215
2
votes
1 answer

How would I grab all articles and order by number of comments?

Possible Duplicate: How would I grab only articles with comments that were created 20 minutes ago? Using mongodb and mongoid. How would one grab all articles and order by number of comments? class Article include Mongoid::Document has_many…
Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215
2
votes
2 answers

Select by subcollection count in mongodb

I have an mongo object like this: { "_id" : ObjectId("4fa291baf5de89b89cb03f4e"), "examples" : [ "!@3123123123", "23423fd34", "23423we4234" ] } I need to select all objects that have >= 3 examples. What is the right way to do…
Benjamin Harel
  • 2,906
  • 3
  • 24
  • 32
2
votes
1 answer

Mongoid 3.0.0 undefined method `master' for Mongoid:Module

Mongoid.master.collection("seq").find_and_modify({ :query => {:_id => self.class.name}, :update => {'$inc' => {:next => 1}}, :new => true, :upsert => true })["next"] It works well in mongoid 2.4.9, but when i use mongoid 3.0.0, i…
doabit
  • 68
  • 6
2
votes
1 answer

undefined method `valid_options' for nil:NilClass with simple_form and Mongoid

I have two models, Category and Post. Category.rb class Category include Mongoid::Document field :title, :type => String has_many :posts, :autosave => true, dependent: :destroy end Post.rb class Post include Mongoid::Document field :title, :type…
hyperrjas
  • 10,666
  • 25
  • 99
  • 198