mongomapper

MongoMapper near with maxDistance - Mongo::OperationFailure: geo values have to be numbers:

自古美人都是妖i 提交于 2019-12-12 12:13:03
问题 I'm trying to encapsulate a near query with a maxDistance in a MongoMapper backed model. I must be doing something silly in my query syntax. Model class Site include MongoMapper::Document key :id, Integer key :name, String key :location, Array ensure_index [[:location, '2d']] def self.nearest(center_point, range) where(:location => {'$near' => center_point, '$maxDistance' => range}).all end end Trying to get everything within 200 miles of a point... Site.nearest([-122.0,44.0],200) > Mongo:

MongoMapper Parent Inheritance

一世执手 提交于 2019-12-12 08:06:58
问题 I am trying to get a better and organized result from using class inheritance with MongoMapper, but having some trouble. class Item include MongoMapper::Document key :name, String end class Picture < Item key :url, String end class Video < Item key :length, Integer end When I run the following commands, they don't quite return what I am expecting. >> Item.all => [#<Item name: "Testing", created_at: Sun, 03 Jan 2010 20:02:48 PST -08:00, updated_at: Mon, 04 Jan 2010 13:01:31 PST -08:00, _id:

Is there a way in MongoMapper to achieve similar behavior as AR's includes method?

孤街浪徒 提交于 2019-12-12 04:49:53
问题 Is there a feature equivalent in MongoMapper to this: class Model < ActiveRecord::Base belongs_to :x scope :with_x, includes(:x) end When running Model.with_x, this avoids N queries to X. Is there a similar feature in MongoMapper? 回答1: When it's a belongs_to relationship, you can turn on the identity map and run two queries, once for your main documents and then one for all the associated documents. That's the best you can do since Mongo doesn't support joins. class Comment include

mongo + passenger: right way to reconnect to database from within rails? how to ensure optimal mongo performance?

自作多情 提交于 2019-12-11 21:08:36
问题 we're on rails 3.2.12, passenger + nginx (1.0.10), mongo 2.2, and mongomapper 0.12. we were told that passenger and mongo don't work well together unless there is a configuration set to ensure speedy database connections (or reconnections). however, one person advised us to use the code here: http://pastie.org/572282. then we found this post on stackoverflow (mongoDB, passenger and performance issues with phusion passenger), which is different. which is the right way to ensure optimal mongo

mongomapper geospatial 'within' query

空扰寡人 提交于 2019-12-11 11:55:01
问题 I'm trying to do a 'within' query using mongomapper. When I execute the command in the shell everything works fine: box = [[32.476750,-117.246094],[32.850173,-116.806641]] db.locations.find({"location" : {"$within" : {"$box" : box}}}) // Bunch of results However, when I run the same in the rails console I get nil: box = [[32.476750,-117.246094],[32.850173,-116.806641]] Location.find(:location => {"$within" => {"$box" => box}}) => nil If I do Location.first I get a location back so I do know

Query is not executing in rails app using mongomapper

ε祈祈猫儿з 提交于 2019-12-11 06:57:03
问题 In my rails application i am writing mongo db query to collections where it should perform AND operation (Example: Basically i want all the user details from collection where city=delhi and gender=male) .I am stuck in this , I am referring to this link . http://mongomapper.com/documentation/plugins/querying.html. Even i have followed the below links MongoMapper OR clause on 2 columns - Rails 3.1.rc4. But nothing is working, I am new to this i dont know is this correct approach or else is

MongoDB: Pulling multiple random documents from a collection

六月ゝ 毕业季﹏ 提交于 2019-12-11 05:17:17
问题 I need to pull multiple random documents from a collection in MongoDB. I don't want to ad a new key to my documents or use a map reduce. Any suggestions? 回答1: You can generate random skip in range from 0 up to collection items count and then load documents: db.items.find().skip(randonNumberHere).limit(1); But, such approach because less and less efficient for a big collections, because each time when you use skip mongodb iterate from first to skip item. 回答2: If the collection isn't

Mongomapper documentation?

喜欢而已 提交于 2019-12-11 04:31:59
问题 I have stumbled upon Mongoid which has great documentation: http://mongoid.org/docs/associations/ But I have heard that MongomMapper is de-facto for Rails. Where do I find API documentation for using Mongomapper? 回答1: The standard answer from the author of MongoMapper is that the project is still young and that the API is still in flux. Download the latest version from Git and look at the tests. You should be able to get a fair idea of what is possible. 回答2: It's up on rdoc.info now: http:/

Heroku rake task uninitialized constant for MongoMapper model

坚强是说给别人听的谎言 提交于 2019-12-11 03:08:54
问题 I have a tiny rake task which just sticks a new delayed job into the queue. I've inserted a debug line desc 'Start processing new rss feed articles' task :process_new_articles => :environment do config = RSS_CONFIG feeds = config['rss_feeds'] puts Article.all feeds.each do |feed| Delayed::Job.enqueue ProcessNewArticlesJob.new(feed, config['settings']) end end It seems to be loading the config info correctly. But I'm getting a "uninitialized constant Article" error upon running the task.

Create a Mongo query in Java using a String

╄→гoц情女王★ 提交于 2019-12-10 23:53:54
问题 Mongo Java driver provides a JSON.parse(String query) method to convert query into DBObject . public void find() { DBObject query = JSON.parse("{name:{$exists:true}}"); DBCursor cursor = collection.find(query); } Using Jackson objects can be un/marshalled the same way: DBCollection collection = new Mongo().getDB("db").getCollection("friends"); public void save() { DBObject document = jsonMarshall(new Friend("John", 24)); collection.save(document); // db.peoples.save({name: 'John', age: 24}) }