I'm trying to implement shoulda unit tests on a rails 2.3.5 app using mongomapper.
So far I've:
Configured a rails app that uses mongomapper (the app works)
Added shoulda to my gems, and installed it with rake gems:install
Added config.frameworks -= [ :active_record, :active_resource ] to config/environment.rb so ActiveRecord isn't us...
I'm using mongo_mapper 0.7.5 and rails 2.3.8, and I have an instance method that works in my console, but not in the controller of my actual app. I have no idea why this is.
#controller
if @friendship.save
user1.add_friend(user2)
...
#model
...
key :friends_count, Integer, :default => 0
key :followers_count, Integer, :default => 0
...
The Source code is
class RealTimeDetail
include MongoMapper::EmbeddedDocument
key :url, String
key :method, String
end
class TargetFeed
include MongoMapper::Document
key :name, String, :null => false
key :feed_type, String, :null => false
has_one :real_time_detail
end
When I do target_feed.real_time_detail = RealTi...
I wanted to try geospatial indexes with MongoDB, but all I get is
> db.map_nodes.find( { coodinate: { $near: [54, 10] } } )
error: { "$err" : "invalid operator: $near" }
and
> db.map_nodes.runCommand({geoNear:"coordinates", near:[50,50]})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"geoNear" : "coordinates",
"n...
Hi all,
I'll admit I'm still new to Ruby and now mongoDB so i'm guessing i'm doing something dumb.
For a test I have this code called tester.rb:
require 'Mongo_Mapper'
MongoMapper.database = "myTestDB"
class Person
include MongoMapper::Document
key :first_name, String
key :last_name, String
end
person = Person.new(:first_name =...
In Ruby, how can I traverse an arbitrary document retrieved from a collection using something like mongomapper? Let's say the document looks something like this:
mydocs =
[{"title":"my title",
"description":"hello world",
"comments":[{"user":"me","text":"this"},{"user":"him","text":"that"}]
},
{.....}
]
...
Embedded vs link
I'm looking for the fastest way to search a Newsletter document for a connected Email. So far I have used MongoMapper with one document for Newsletter and another for Email. This is getting really slow with +100k Emails.
I was thinking maybe its faster to embed the emails in an array inside Newsletter
since I'm really ...
hi
i have a rails app that currently uses activerecord to store and query products.
Each product has a category and sub category and each sub category is defined by multiple field that i can create within the application. From this when a user wants to input a specific product, they are pressented with the relevent form fields.
This ...
I'm new to MVC. I'm using Padrino with MongoMapper and Haml to try to create this application.
I have a database of items, each of which has a hash associated with it called 'params'. This hash has some required keys, but mostly arbitrary/random keys. Some of the keys have a finite set of allowable values.
For example:
item.params["pa...
Hi there,
I'm a mongo + mongomapper newbie, my question is, after following the
examples in these slides:
1. http://www.slideshare.net/mongosf/ruby-development-and-mongomapper-john-nunemaker/39
2. Slide 40
3. Slide 41
I ended up with 2 collections joined on a foreign id... Is that right?
I was expecting to see something similar to what...
This example makes it seem like both are used (included) in order to make a class a persistent model, but it is not clear when I should use one or the other.
...
I have a MongoMapper model and am trying to convert a comma-delimited string into an Array to be stored.
The main problem is that a string such as tags = "first,second,third" is not getting converted to an array in the database like ["first","second","third"]. Instead it is going in as ["first,second,third"].
There are some other stran...
Could I declare a model with a key called :key, for instance? Is there any word I can't use for a key?
...
I'm trying to write a plugin that defines a MongoMapper model. The problem is that when I run script/console, I get this error:
/home/helder/.rvm/gems/ruby-1.8.7-p249/gems/mongo_mapper-0.8.2/lib/mongo_mapper/connection.rb:29:in
`database':NameError: uninitialized class variable @@database_name in MongoMapper::Connection
which leads me ...
How do I do the following in one operation:
Find or create object by some key:value pairs
Increment properties on the object.
I am doing this now:
Model.find_or_create_by_this_and_that(this, that).increment("a" => 1, "b" => 1)
What's the correct way to do that?
...
I'm playing around with MongoMapper and have cloned the repository. I'd like to start modifying the code but am new to Rails and am not sure how to do this.
...
When adding a key to an existing model (with existing data) via MongoMapper, I can create new documents with the new key but when trying to access existing documents using that same key it fails stating that it's an "undefined method."
I was wondering if anyone had any insight.
Thanks in advance!
(Yes, these examples are truncated.)
...
hi all
I am trying to work out the best way to store my daat using mongodb and mongomapper.
I have category and each category can be described by many attributes so length in mm, weight in kg etc.
I want each user to be able to create their own attributes to descibe a category of products.
So forexample:
user A wants to store his c...
What's the recommended way to do the following:
class Property
include MongoMapper::Document
key :key
key :value
belongs_to :post
end
class Post < ActiveRecord::Base
has_many :properties
end
Does that work (testing now)?
Update, adding this to ActiveRecord is a start:
ActiveRecord::Base.class_eval do
def new?
new_...
hi all
I have a category collection and each category has a array of hashes containing attributes names and units to create a inout form with, to add a product of that category.
for example category car fields - {name : length, unit : mm}, {name : weight, unit : kg}.
Problem is i would this site to be multi-lingual and therefore need ...