Sorting a Query Fos Elastica - foselasticabundle

I have a Query to matchAll product in ElasticSearch. It run perfeclty but I want to add a Sort for this Query. I don't find example which run and I don't understand why it generate error.
This code for sorting query :
$match = new \Elastica\Query\MatchAll();
$query = new \Elastica\Query($match);
$query->addSort([
'product.price' => ['order' => 'asc']
]);
return $this->find($query);
Generate this error :
Error: Wrong parameters for Exception([string $exception [, long $code
[, Exception $previous = NULL]]])
I try lot of thing before post this but the error is always the same.
ElasticSearch : 5.2.2
FosElasticaBundle : 3.2.2
PHP : 5.6.30
Symfony : 2.8

This error means that is a incompatibility between ES, Elastica and FosElasticBundle. Warning ES and base PHP labrary Elastica...
this code run perfectly :
$query = new Query();
$queryRange = new \Elastica\Query\Range('product.price', array('gt' => 0, 'lt' => 20));
$query->setQuery($queryRange);
return $this->find($query);
ElasticSearch : 1.7.4
FosElasticaBundle : 3.2.2
PHP : 5.6.30
Symfony : 2.8

Related

MongoDB Visual Studio Code extension: how to find by ObjectId

I'm using the following extension:
https://code.visualstudio.com/docs/azure/mongodb
To perform queries and light data transformation against a Mongo database. I'm having trouble working out how to issue a find request which matches an ObjectId.
I tried:
db.Epochs.find({
'ModelId': '624616797870316ac1432d52'
}).sort({'End': -1})
This results in an empty result set (this ID definitely exists because I copied that value from Compass.
I tried:
db.Epochs.find({
'ModelId': ObjectId'624616797870316ac1432d52')
}).sort({'End': -1})
Which results in the following error:
Unexpected token, expected "," (15:23) 13 | 14 | db.Epochs.find({ > 15 | 'ModelId': ObjectId('624616797870316ac1432d52') | ^ 16 | }).sort({'End': -1}) 17 | 18 | //'EndLogs._impl': { '$exists': true}
I tried adding the NodeJS driver setup calls like:
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');
Which errors with:
Cannot find module 'mongodb' Require stack: - c:\Users\Ian\.vscode\extensions\mongodb.mongodb-vscode-0.9.2\dist\languageServerWorker.js
Finally I tried:
db.Epochs.find({
'ModelId': { '$oid': '624616797870316ac1432d52' }
}).sort({'End': -1})
Which errors with:
unknown operator: $oid

Ruby date format for PayPal Button Manager API

I can't get a date format that PayPal will accept via its PayPal Button manager API. "The start date specified is invalid." is the error.
Attempt 1: copy the string directly from the documentation:
"start_date": "2017-12-22T09:13:49Z"
I saw this https://github.com/paypal/PayPal-Ruby-SDK/issues/107 so tried
strftime('%Y-%m-%dT%H:%M:%SZ') and utc.iso8601
start_date = "1980-02-19T00:37:04Z"
start_date = (DateTime.now - 10.years).utc.iso8601
start_date = (DateTime.now - 10.years).utc
#bm_build_button_search = #api.build_bm_button_search({ "start_date" => start_date })
# Make API call & get response
#bm_button_search_response = #api.BMButtonSearch(#bm_build_button_search)
#Errors=[#<PayPal::SDK::ButtonManager::DataTypes::ErrorType:0x007fa58b12e110 #ShortMessage="Invalid Argument", #LongMessage="The start date specified is invalid.", #ErrorCode="11998
(byebug) #bm_build_button_search.start_date.class
PayPal::SDK::Core::API::DataTypes::SimpleTypes::DateTime
So it looks like PayPal is fine with this DateTime format but when I call
#api.BMButtonSearch(#bm_build_button_search)
I get the error #LongMessage="The start date specified is invalid."
I just verified following script using Ruby version 2.3.3 and its working fine. Following is the script i used in ruby console.
Step1: install Paypal SDK
$ gem install paypal-sdk-buttonmanager
Step2:
require 'paypal-sdk-buttonmanager'
#api = PayPal::SDK::ButtonManager::API.new(
:mode => "sandbox", # Set "live" for production
:app_id => "APP-80W284485P519543T",
:username => "jb-us-seller_api1.paypal.com",
:password => "WX4WTU3S8MY44S7F",
:signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-
RWy" )
Step3:
start_date = "1980-02-19T00:37:04Z"
#bm_build_button_search = #api.build_bm_button_search({ "start_date" => start_date })
#bm_button_search_response = #api.BMButtonSearch(#bm_build_button_search)
Response: I, [2017-05-06T05:43:14.803444 #6541] INFO -- : Action: BMButtonSearch
I, [2017-05-06T05:43:14.803551 #6541] INFO -- : Request[post]: https://api-3t.sandbox.paypal.com/2.0/
I, [2017-05-06T05:43:27.057413 #6541] INFO -- : Response[200]: OK, Duration: 12.254s
**Please verify using Ruby 2.3.3. Screenshot has been attached. thanks!**
reference: https://github.com/paypal/buttonmanager-sdk-ruby

greater than symbol for find() method in php7 mongodb

I am developing a php-mongodb project. I have installed the php-mongodb driver using composer. connectivity is working fine.
used reference link for any guidance :
http://mongodb.github.io/mongo-php-library/tutorial/crud/#crud-operations
and http://php.net/manual/en/mongocollection.find.php
I could not find much reliable theory for php-7 except those.
How to fire a query with php-7 to get a result from database greater than specified number?
The code I tried is :
$rs=$collection->find(['$gte'=>['avg'=>50]]);
this is not working. The error it produced was:
Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionException: unknown top level operator: $gte in /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Operation/Find.php:180 Stack trace: #0 /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Operation/Find.php(180): MongoDB\Driver\Server->executeQuery('training.tbl', Object(MongoDB\Driver\Query), Object(MongoDB\Driver\ReadPreference))#1 /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Collection.php(437): MongoDB\Operation\Find->execute(Object(MongoDB\Driver\Server)) #2 /var/www/example.com/public_html/list.php(5): MongoDB\Collection->find(Array) #3 {main} thrown in /var/www/example.com/public_html/vendor/mongodb/mongodb/src/Operation/Find.php on line 180
found this answer from following here
// search for documents where 5 < x < 20
$rangeQuery = array('x' => array( '$gt' => 5, '$lt' => 20 ));
for above example the answer comes to be:
$rangeQuery = ['avg' => ['$gt' => '50' ]];
$rs=$collection->find($rangeQuery);

Using a string as a RID with SQL Commands

Using the Java api on an Orient-DB 2.0 rc1. Is it possible to use a string as a RID?
Documentation : https://github.com/orientechnologies/orientdb/wiki/SQL-Update#example-3-add-a-value-into-a-collection
more specifiaclly the section SQL Commands
JSON received:
{
userRID:"#100:100",
group:"someCode"
}
JAVA CODE (xtend script):
def addUserInGroup(Message<JsonObject> message){
val params = new JsonObject() => [
putString("userId", message.body().getString("userRID"));
putString("code", message.body().getString("group"));
]
var queryCommand= "update Table add users=:userId where code=:code";
Map<String, Object> paramsFormatted = params.toMap();
database.command( new OCommandSQL(queryCommand) ).execute(paramsFormatted);
}
Table structure :
users : linklist (user object)
code : string
When I run the following commands in the studio they all work :
update Table add users=(Select #rid from User where #rid=#100:100) where code='someCode'
update Table add users=#100:100 where code='someCode'
But none of these command work in the API. I'm guessing there is something wrong in way I'm using the RID.
SEVERE: Exception in Java verticle
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #29: Found unexpected keyword '=:USERID' while it was expected '[=]'. Use UPDATE <class>|cluster:<cluster>> [SET|ADD|PUT|REMOVE|INCREMENT|CONTENT {<JSON>}|MERGE {<JSON>}] [[,] <field-name> = <expression>|<sub-command>]* [LOCK <NONE|RECORD>] [UPSERT] [RETURN <COUNT|BEFORE|AFTER>] [WHERE <conditions>]
Command: update SecureAccess add users=:userId where code=:code
-------------------------------------^
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract.throwSyntaxErrorException(OCommandExecutorSQLAbstract.java:89)
at com.orientechnologies.common.parser.OBaseParser.parserRequiredKeyword(OBaseParser.java:317)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parseAddFields(OCommandExecutorSQLUpdate.java:605)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:129)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:59)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:56)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:37)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1150)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:63)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1179)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:385)
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:216)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:65)
janv. 07, 2015 8:45:17 AM org.vertx.java.core.logging.impl.JULLogDelegate error
SEVERE: Exception in Java verticle
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #29: Found unexpected keyword '=:USERID' while it was expected '[=]'. Use UPDATE <class>|cluster:<cluster>> [SET|ADD|PUT|REMOVE|INCREMENT|CONTENT {<JSON>}|MERGE {<JSON>}] [[,] <field-name> = <expression>|<sub-command>]* [LOCK <NONE|RECORD>] [UPSERT] [RETURN <COUNT|BEFORE|AFTER>] [WHERE <conditions>]
Command: update SecureAccess add users=:userId where code=:code
-------------------------------------^
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract.throwSyntaxErrorException(OCommandExecutorSQLAbstract.java:89)
at com.orientechnologies.common.parser.OBaseParser.parserRequiredKeyword(OBaseParser.java:317)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parseAddFields(OCommandExecutorSQLUpdate.java:605)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:129)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:59)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:56)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:37)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1150)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:63)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1179)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:385)
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:216)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:65)
I think You should try something like :
putString("userId", new ORecordId(message.body().getString("userRID")));

mongodb not letting writes go through

Writing to Mongodb via Java Driver. Getting the following error:
com.mongodb.WriteConcernException: { "serverUsed" : "127.0.0.1:27017" , "err" : "_a != -1" , "n" : 0 , "connectionId" : 3 , "ok" : 1.0}
at com.mongodb.CommandResult.getWriteException(CommandResult.java:90)
at com.mongodb.CommandResult.getException(CommandResult.java:79)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:131)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:135)
at com.mongodb.DBTCPConnector.access$000(DBTCPConnector.java:39)
at com.mongodb.DBTCPConnector$1.execute(DBTCPConnector.java:186)
at com.mongodb.DBTCPConnector$1.execute(DBTCPConnector.java:181)
at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:210)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:181)
at com.mongodb.DBCollectionImpl.insertWithWriteProtocol(DBCollectionImpl.java:528)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:193)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:165)
at com.mongodb.DBCollection.insert(DBCollection.java:161)
at com.mongodb.DBCollection.insert(DBCollection.java:147)
at com.mongodb.DBCollection$insert.call(Unknown Source)
Can't find any reference in docs to "err" : "_a != -1". Any thoughts?
EDIT:
Adding code I used (not all as it relies on other libraries to parse files):
MongoClient mongoClient = new MongoClient()
mongoClient.setWriteConcern(WriteConcern.SAFE)
DB db = mongoClient.getDB("vcf")
List<DBObject> documents = new ArrayList<DBObject>()
DBCollection recordsColl = db.getCollection("records")
//loop through file
BasicDBObject mongoRecord = new BasicDBObject()
//add data to mongoRecord
documents.add(mongoRecord)
//end loop
recordsColl.insert(documents)
mongoClient.close()