Searchkick boost_by_distance gives undefined method `reverse' - searchkick

What am I missing here? I simply copy paste the example on https://github.com/ankane/searchkick to the console and I get an error.
2.2.2 :001 > User.search "jim", boost_by_distance: {field: :location, origin: {lat: 37, lon: -122}}
NoMethodError: undefined method `reverse' for {:lat=>37, :lon=>-122}:Hash

Try upgrading to the latest version of Searchkick (1.1.1).

I was trying to sort the results by distance. Ended up using this query instead:
order: {_geo_distance: {coordinates: "#{find_coordinates[1]},#{find_coordinates[0]}", order: "asc", unit: "mi"} }
While I grab the coordinates from the ip with Geocoder:
def find_coordinates
Geocoder.coordinates(request.remote_ip)
end

Related

PyMongo : Array filtered positional operator update gives me error

I am trying to run a python code to update a collection with arrays. The below statement give error wtih pymongo . Please guide
db.students.update({}, {'$set': {"grades.$[element]": 100}}, {'multi': true, 'arrayFilters': [{"element": { '$gte': 100}}]} )
tried : multi=True tried : multi:True
I am getting the below error :
common.validate_boolean("upsert", upsert)
File "F:\Program Files\Python3.7\lib\site-packages\pymongo\common.py", line 159, in validate_boolean
raise TypeError("%s must be True or False" % (option,))
TypeError: upsert must be True or False
Pymongo's syntax is a tad different than Mongo's syntax, you should write it like this:
db.students.update({}, {'$set': {"grades.$[element]": 100}}, multi=True, array_filters=[{"element": {'$gte': 100}}])
Also update is deprecated, and in your case you should use update_many instead.
db.students.update_many({}, {'$set': {"grades.$[element]": 100}}, array_filters=[{"element": {'$gte': 100}}])

SoftLayer_Virtual_Guest setTransientWebhook

I'm looking for a sample code using SoftLayer_Virtual_Guest::setTransientWebhook for Transient VSI. Is there a sample code?
Thanks
Behzad
Try with next requests:
Method GET
http://api.softlayer.com/rest/v3.1/SoftLayer_Account/getVirtualGuests?objectMask=mask[id,transientGuestFlag]&objectFilter={"virtualGuests":{"transientGuestFlag":{"operation": 1}}}
Data 1 means true also 0 means false, in this case, we use one with data 1
Choose the VSI id you want to set and use the following request:
Method POST
http://api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/111111/setTransientWebhook
Body
{"parameters":[
"https://test1.com",
"testsupport"]
}
The 111111 data is the VSI that we chose in the previous request.
Reference
https://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest/#transientGuestFlag
https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/setTransientWebhook/
I hope it helps you
Thanks Daniel, would this be equivalent code in python: request = client['Virtual_Guest'].createObject({
'hostname': hostname,
'domain': domainname,
'startCpus': cpus,
'maxMemory': memory,
'hourlyBillingFlag': 'true',
'datacenter': {'name': 'tor01'},
'operatingSystemReferenceCode': os_code,
# 'localDiskFlag': 'false',
"supplementalCreateObjectOptions": {"flavorKeyName": "C1_1X1X25"},
'transientGuestFlag': 'true',
# 'sshKeys': [{"id":201867}]
"parameters":["https://test1.com","testsupport"].

GORM standalone: no updateOne() with maps

In my good'ol grails (3.1.x) app I have lines like
ModuleState.collection.updateOne(
[ compositeKey:ck ],
[ $set:[ compositeKey:ck, dateUpdated:new Date(), online:true ] ],
[ upsert:true ] )
In my grails-free app with GORM standalone:
compile 'org.grails:grails-datastore-gorm-mongodb:6.0.4.RELEASE'
this line throws an exception
groovy.lang.MissingMethodException: No signature of method: com.mongodb.MongoCollectionImpl.updateOne() is applicable for argument types: (java.util.LinkedHashMap, java.util.LinkedHashMap, java.util.LinkedHashMap) values: [[compositeKey:111], [$set:[...]], ...]
Possible solutions: updateOne(org.bson.conversions.Bson, org.bson.conversions.Bson), updateOne(org.bson.conversions.Bson, org.bson.conversions.Bson, com.mongodb.client.model.UpdateOptions)
so, the new map-consuming methods are not injected.
Any way to fix it and make GORM great again?
You need to add org.grails:grails-datastore-gorm-mongodb-ext:6.0.4.RELEASE to your classpath

Phoenix Repo.insert out of controller

I'm making a task that get an json in an api and insert in MongoDb. I'm using phoenix and Mongodb_Ecto.
I have a model Group and this code in a controller works like a charm:
HTTPoison.start
group = %Group{ param1: "value", param2: "value" } |> Repo.insert!
But,in a task I don't have the Repo defmodule. I tried to make this:
HTTPoison.start
group = %Group{ param1: "value", param2: "value"} |> MyApp.Repo.insert!
Using MyApp.Repo instead of only Repo.
I'm receiving this error:
** (exit) exited in: :gen_server.call(MyApp.Repo.Pool, {:checkout, #Reference<0.0.1.11>, true}, 5000)
** (EXIT) no process
:erlang.send(MyApp.Repo.Pool, {:"$gen_cast", {:cancel_waiting, #Reference<0.0.1.11>}}, [:noconnect])
(stdlib) gen_server.erl:416: :gen_server.do_send/2
(stdlib) gen_server.erl:232: :gen_server.do_cast/2
src/poolboy.erl:58: :poolboy.checkout/3
(stdlib) timer.erl:197: :timer.tc/3
lib/mongo/pool/poolboy.ex:33: Mongo.Pool.Poolboy.run/2
lib/mongo/pool.ex:142: Mongo.Pool.run_with_log/5
lib/mongo.ex:220: Mongo.insert_one/4
lib/mongo_ecto/connection.ex:124: Mongo.Ecto.Connection.catch_constraint_errors/1
lib/mongo_ecto.ex:522: Mongo.Ecto.insert/6
lib/ecto/repo/model.ex:253: Ecto.Repo.Model.apply/4
lib/ecto/repo/model.ex:83: anonymous fn/10 in Ecto.Repo.Model.do_insert/4
lib/ecto/repo/model.ex:14: Ecto.Repo.Model.insert!/4
How can I access Repo.insert in the correct way to save my data in mongoDb?
Thanks for this.
Your application (and therefore your database pool) is not started automatically in a Mix task. You can start it manually by adding the following:
:application.ensure_all_started(:my_app)
If :httpoison is listed in your Mixfile's :applications, you don't need to do HTTPoison.start anymore as the above line will ensure :httpoison is started before :my_app.

Ionic with ui-router.stateHelper

Is it possiable to use ionic with ui-router.stateHelper
I want to use this for help me working with nested views:
the property children is what I'm looking for.
If its not possible, how can i do something similar, without defining each child state with name: parent.child?
after installing and import im getting the next error:
TypeError: Cannot read property '#' of undefined at updateView (http://localhost:8100/lib/ionic/js/ionic.bundle.js:62199:69)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:62194:9
at invokeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21830:9)
at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21330:11)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20721:13)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20725:13)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20725:13)
at publicLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20596:30)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:14815:27
at Scope.$eval (http://localhost:8100/lib/ionic/js/ionic.bundle.js:29026:28) <ion-nav-view class="view-container" nav-view-transition="ios">
Ok This is working.. I had problem with the indjection.
this is the right way: (im using browserify)
npm install angular-ui-router.statehelper
then in the package.json
under browser:
"angular-ui-router-helper": "./node_modules/angular-ui-router.statehelper/statehelper.min.js"
and under browserify-shim
"browserify-shim": {
"angular": "angular",
"ionic": "ionic",
"angular-ui-router-helper": {
"exports": "angular.module('ui.router.stateHelper')"
}
},
and then in the index.js:
var rootModule = angular.module('AppName', ['ionic',require('angular-ui-router-helper').name]);
Then u can inject the stateHelperProvider to the config method :)