Using mongomapper to execute server runCommand geoNear - ruby-on-rails

I would very much like to use the mongo geoNear command as discussed here.
Here is the command I entered in my rails console with the accompanying error message.
MongoMapper.database.command({ 'geoNear' => "trips", 'near' => [45,45]})
Mongo::OperationFailure: Database command 'geoNear' failed:
(errmsg: 'more than 1 geo indexes :('; ok: '0.0').
I can not make sense of the error message, it is supposedly impossible to have more than 1 geo index and I am certain that I have only created one.
Based on this stackoverflow question I believe I am wording the query correctly. Does anyone understand that error message? How would I go about destroying and recreating my indexes?
I am using rails 3.1 with mongodb v2.0 and the mongo ruby gem v1.5.1.

I really asked this too soon, maybe I should delete it? Somehow there were in fact too many geo indexes, because deleting the index and recreating it fixed the problem.
MongoMapper.database.collection('trips').drop_indexes
Trip.ensure_index [[:route, '2d']]

Related

Randomly lost data on activeadmin

I have a weird problem with activeadmin. Randomly and unexpectedly some data on a resource not showed (like it has benn empty in DB). When I check the DB, all data it is on db and it is correct.
Also the data when take some .json resource is empty too.
The only solution I found for this problem is restart nginx, but it is a problem because the client not see the information on the system.
I check the logs, but I do not see any relevant information. Is there any way to get information about it for solve this kind of problems?
System versions:
Rails 5.1.3
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-linux]
nginx/1.10.3 Phusion_Passenger/5.1.4
Finally I found the problem but I do not understand what is wrong on it....
This are the involucrated files:
https://gist.github.com/cpfarher/bfde79dd9c3772575b03712c0a397110
The problem occured when you open the route: lines/1/edit action. After open it, data on https://gist.github.com/cpfarher/bfde79dd9c3772575b03712c0a397110#file-admin_recipe-rb is not showed.
If you change de sentence "select distinct" on line:
https://gist.github.com/cpfarher/bfde79dd9c3772575b03712c0a397110#file-recipe_fail-rb-L10
all works fine, the field on https://gist.github.com/cpfarher/bfde79dd9c3772575b03712c0a397110#file-admin_recipe-rb-L13 showed ok. But, if you use the clause with select distinct, the field it is not showed....
On the other hand if you use the file: https://gist.github.com/cpfarher/bfde79dd9c3772575b03712c0a397110#file-recipe_ok-rb instead of https://gist.github.com/cpfarher/bfde79dd9c3772575b03712c0a397110#file-recipe_fail-rb all works fine.... :|

neo4jrb DeprecatedSchemaDefinitionError

I've a problem with Neo4jrb 8.1.1, Rails 5.1.1, Neo4j 3.2.0 CE
I have a City model with an Int id, the DB is read only with data imported from csv files.
What should I declare to get rid of the error?
So far, I thought that declaring
id_property :id
property :name
would be fine but it doesn't work.
Overall, I'm annoyed with these new migrations files because the Neo4J DB is already done, I'm not supposed to write or modify indexes or constraints.
What's the error message you're seeing? I imagine you can solve the issue by creating an initializer and manually adding the relevant constraint(s) to the ModelSchema. Something like Neo4j::ModelSchema.add_defined_constraint(City, :id). It's also possible that this could be done inside the Model itself. Some experimentation should solve the problem.
See the source code for more info:
https://github.com/neo4jrb/neo4j/blob/8.1.x/lib/neo4j/model_schema.rb
http://www.rubydoc.info/gems/neo4j/Neo4j/ModelSchema

What is the source of "unknown OID" errors in Rails?

When replicating an app to production, my POSTGIS table columns started misbehaving, with Rails informing me there was an "unknown OID 26865" and that the fields would be treated as String.
Instead of current_pos yielding e. g.
#<RGeo::Geographic::SphericalPointImpl:0x22fabdc "POINT (13.39318248760133 52.52908798020595)"> I would get 0101000020E6100000FFDD958664C92A403619DEE6B2434A40. It looked like the activerecord-postgis-adapter was not installed, or installed badly, but I eliminated that possibility by testing for the existence of data type RGeo::Feature::Point and by test-assigning
current_pos = "POINT (13.39318248760133 52.52908798020595)"
to the field - which proceeded without error but then yielded another incomprehensible hex string like the above.
Also, strangely enough, POSTGIS was working correctly within the database, e.g. giving correct results for a ST_DISTANCE query. A very limited problem thus, where writing, writing-parsing (from Point to hex format), manipulating by SQL and reading all worked, only the parsing upon read didn't.
When I tried to use migrations to ensure the database column would have the correct type, the migrations failed, giving
undefined method `st_point' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x00000005cb80b8>
I spent several hours trying all kinds of solutions, even re-installing the server from scratch, double-checking version numbers of everything, installing a slightly newer version of Ruby and a slightly older version of POSTGIS (to match my other environment), exporting the database and starting with a clean one, and so on. After I had done migrations and arrived at the "undefined method st_point" error, I was finally able to find the solution via Google, way down in a Github issue, and it's really simple:
In config/database.yml, swap out postgres:// for postgis:// in the database url. If you're using Heroku, this may require some ugly manipulation:
production:
url: <%= ENV.fetch('DATABASE_URL', '').sub(/^postgres/, "postgis") %>
So silly...
Do not forget to add activerecord-postgis-adapter to your Gemfile so #Sprachprofi's solution can run.

pry raise an error using show-models with neo4j

I just switched rails console to use pry.
I'm also using ruby 2.1.2p95, rails 4.1.5, neo4j (3.0.0.alpha.11), neo4j-community (2.1.3), neo4j-core (3.0.0.alpha.19)
While executing the command show-models it failed, returning the following error:
[3] pry(main)> show-models
ArgumentError: wrong number of arguments (1 for 2..3)
from /home/pdipietro/.rvm/gems/ruby-2.1.2/bundler/gems/neo4j-2e41203410cc/lib/neo4j/active_node/has_n.rb:79:in `has_one'
has anyone an idea on how to circunvent it?
Thank you
Paolo
Look in your models, one of them has a bad has_one call. Every has_one requires at minimum two parameters: a direction and an association name. That indicates you have one that's probably using the old syntax, just doing has_one :association. See documentation at https://github.com/neo4jrb/neo4j/wiki/Neo4j-v3-Declared-Relationships.
EDIT: Unfortunately, I just tested and it doesn't look like show-models doesn't recognize these models. You can add an issue at https://github.com/neo4jrb/neo4j and we can work on adding support. The error you're reporting still has nothing to do with pry, though.
Also, 3.0.0.alpha.11 is quite old at this point, the gem has been released and is now up to 3.0.1. You should really update.

Phusion Passenger Error using .all function - is there a backwards compatible method?

I previously posted a question (Performing multiple queries on the same model efficiently) which fellow StackExchange users kindly answered and saved me lots of processing time, avoiding lots of queries on my model by storing the results of a SQL query using the .all function
Specifically they advised #chosenrecords = Everything.where('name LIKE ?', 'What I want').order('price ASC').all be used
This appeared to work fantastically and I used it in a number of places in our code, however, having just uploaded it onto a live server I get an error message from Phusion Passenger for every line in which .all features.
The error is syntax error, unexpected '.', expecting kEND .order('price ASC').all
I have previously tried to gather information from the company hosting our sites regarding the versions of rails and passenger they're using, but without any success. In the past anything that has worked locally has also worked on the server, provided I use Ruby 1.9.3 i386-mingw32.
Can anyone advise how I could fix this error? Is there an older function that does the equivalent operation and may work on the server?
Discovered that the old version of Passenger appears to be less robust to code falling across 2 lines, essentially I changed
#chosenrecords = Everything.where('name LIKE ?', 'What I want')
.order('price ASC').all
to the following and it works a dream
#chosenrecords = Everything.where('name LIKE ?', 'What I want').order('price ASC').all
Hopefully someone else will benefit from the errors of my ways!
Actually that's not a Passenger problem, nor is it a matter of "less robust to code falling across 2 lines". The problem is this:
The first code exhibit is illegal Ruby syntax. If you to chain a to #order like that, you have to ensure that the first line ends with a dot. Otherwise Ruby will think that the first line is a single, complete statement, with the second one also being a single complete statement. Obviously a Ruby statement cannot begin with a dot, so in your first code exhibit, the second line raises a syntax error.

Resources