Create a model (RAILS) for mongoid

I have to connect my Rails app to MongoDB, after some research i found a gem (mongoid). My doubt is, how to create the model? The collection on MongoDB looks like the example bellow: { "_id": { "$oid": "56fbf7e577550f39a5aea04a&qu

How to make a request for Mongoid documents by two references

I'm using Mongoid on this project. Lets say I have a model like so: class Voice include Mongoid::Document include Mongoid::Timestamps include Mongoid::Enum include Mongoid::Paperclip enum :status, [:enabled, :disabled], :validate => true, :default =>

Deleting the index of a collection in mongoDB?

I want to remove the id of my document in MongoDB. I will put the document below: { "_id" : ObjectId("54f2324671eb13650e8b4569"), "nome" : "Pr.Ademar Lourenço", "tweet" : "Jornal Águas Lindas: Prefeit

Mongoid rails `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 3.1.0 I

how to check validation mongodb id with php

i get mongodb id of query string. how to check validation this id? i want if mongodb id not valid redirect to another url get query string: if(count($_GET)>0 && $_GET['uid']){ //get id from string query $query = array("_id" => new

Ruby on Rails with Mongoid

I have a rails app with mongoid where I am trying to insert a document to the collection using the following code. It works perfectly well in my dev environment where I have straight up mongo, with rails. However in live(where I dont have much contro

Mongoid Multiple Atomic Operations

I have a kind of Mongoid::Document in memory. I want to atomically inc and push in the same call. Mongoid::Criteria only exposes these operations individually. my_model = SomeModel.find "foo" Bad: my_model.inc foo: 1 my_model.push bar: "b&q

Custom user authentication on Rails 4

I'm trying to learn and use my own user model and authentication with Ruby on Rails 4.0, but most tutorials (if not all) seem to be outdated with this recent update. No method described on any of them works. I'm absolutely clueless, this is my User m

RoR: Mongoid and form create hash

Simple question for Rails gurus. Why I do have to use the following statement to insert a new Mongoid document : params[:video][:description] in the following create method of my VideosController? Why I can't use the params[:description] from the POS

Changing the name of the Mongoid class during production

Is this even possible? I have a mongoid class named Magazine, with some associations as well, that I would like to re-name to Publication. Problem is that I already have a bunch of users who have already made magazines, issues and articles. Original

Date ranges overlapping Mongoid and Rails

I'm working on a project that places "bookings" for a particular property. In order to prevent a property from being double booked, I am trying to return a result of properties that are unavailable during a given time frame. In my Booking model,

Mongoid upsert fields

I would like to use the mongoid's upsert method but it should check the document existence on fields different than _id (mongoimport command allows you to do this with --upsertFields option). Is there a way to do this with mongoid?I'll answer my own

Mongoid update_attributes creates a new referenced document

I'm having trouble using update_attributes with referenced documents. I've reduced my problem to a simple example that AFAICT should work, but doesn't: class Account include Mongoid::Document has_many :submissions, :autosave => true end class Submiss

How to get separate results from a Mongoid criterion?

I am very frustrated as I try to query the results of a Mongoid criteria and keep only the documents where a field is distinct. And doing this: Books.all.distinct(:name) ..only returns the name fields, not the documents. Also using the uniq loop as s

Ruby on rails access template information to another template

I have my first model Contact with the field :email and I need this same field :email in my model Customer with the value of the field :email which is in my model Contact. I use mongoID for ORM so here's my first model Contact class Contact include M

How to extract attributes from a collection into a table

If I have a class that looks like below, how to I pull out just the last name from each instance a collection into an array? class Person include :Mongoid::Document field :first_name field :middle_name field :last_name field :email_address end Person

Mongoid: search a table

Is it currently possible to search an array of BSON::OrderedHashes with Mongoid based objects? One of my attributes, let's call it foo in the bar class, looks something like the following: [#<BSON::OrderedHash:0x7f0 {"id"=>"4bf58dd8d4

Convert the string to a currency format

Using Ruby and Haml, I have a property which is cost. I believe (im new to ruby) that it will be a Float At the moment the below line outputs my decimal in format like 4.5 instead of 4.50, which is what I want. %span.value= "£#{event.beers.first.cost

ConnectionFailure using mongo in the rails 3.1

I have an app setup with Rails 3.1, Mongo 1.4.0, Mongoid 2.2.4. What I am experiencing is this: Mongo::ConnectionFailure: Failed to connect to a master node at localhost:27017 I've had this problem before, but it went away on a computer restart... th

Mongolian integrated document reminders

I have a following model with mongoid rails3 class Address include Mongoid::Document embedded_in :person, :inverse_of => :address after_validation :call_after_validation before_validation :call_before_validation before_update :call_before_update afte

Geocoding Gem for Mongoid

Is there a geocoding gem similar to acts_as_geocodable for Mongoid? So far as I can tell all geocoding gems seem to be built for ActiveRecord.Geocoder seems to work with mongoid http://www.rubygeocoder.com/ There is also a nice screencast here http:/

Field aliases in Mongoid

Does anyone know if Mongoid has built in support to alias field names? I've been running some tests where I have a collection with a minimal amount of fields (7 fields). If I use descriptive names and load real data and then use greatly shortened nam