How to find edges with Spring Data ArangoDB - spring-data

When using AQL directly to find edge documents, with a query like
FOR x IN coll1ToColl2 FILTER x._from == 'coll1/1234' RETURN x
the expected edge documents are returned, but when supplying 'coll1/1234' to a Spring Data ArangoDB repository query method like:
#Query("FOR x IN coll1ToColl2 FILTER x._from == #from RETURN x")
Iterable<Coll1ToColl2> findEdgesFromColl1(#Param("from") String from);
the response is null.
How can edges be retrieved with Spring Data ArangoDB?
I'm using version 3.1.1 of the framework against version 3.4.0 of the database.

Related

Mongo Template Results not getting Mapped after Spring Boot Upgrade

After upgrading from Spring boot 2.2.6.RELEASE to 2.4, the following mapping does not work & returns null for all the mapped values. I'm unable to find any mongo documentation describing any update to aggregation or mapping. However the rawResults contains the required data. I've tried changing the mongo versions, spring boot version upgrades.
The same code works without a issue in spring boot 2.2.6.RELEASE version.
final Aggregation agg = newAggregation(match(Criteria.where("id.cid").is(cId)),
group("sId.assignmentId", "status").count().as("total"),
sort(Sort.Direction.DESC, "sId.assignmentId", "status"));
final AggregationResults<StatusSummeryDTO> groupResults = mongoTemplate.aggregate(agg,
Submission.class, StatusSummeryDTO.class);
return groupResults.getMappedResults();
Turns out after MongoDB driver version being changed from 3.x to 4.x in the result DTO class we will need to specify the exact field value using #Field annotation. Unlike in 3.x it does not map automatically which resulted in the above issue.
Since there are breaking changes in the aggregation when moving from 3.x to 4.x I thought that might be the issue. to be on the better side I've changed my code to be compatible with 4.x using new classes as follows.
MatchOperation match = match(Criteria.where("id.cid").is(cId));
GroupOperation group = group("sId.assignmentId", "status").count().as("total");
SortOperation sort = sort(Sort.Direction.DESC, "sId.assignmentId", "status");
Aggregation agg = newAggregation(match, group, sort);
AggregationResults<StatusSummeryDTO> groupResults = mongoTemplate.aggregate(agg, Submission.class, StatusSummeryDTO.class);
return groupResults.getMappedResults();

Azure MongoDB + Synapse Link: Column values unexpectedly contain JSON

I'm following this tutorial and have created an Azure MongoDB (Mongo API) and a Synapse Workspace, imported the ECDC data into MongoDB and connected it in Synapse Workspace. So far so good.
However, when I query the data, for e.g. string column date_rep I get
{"string":"2020-12-14"} instead of just 2020-12-14
The query I'm using is:
SELECT TOP 10 *
FROM OPENROWSET(​PROVIDER = 'CosmosDB',
CONNECTION = 'Account=analytcstest;Database=ecdc',
OBJECT = 'ecds',
SERVER_CREDENTIAL = 'analytcstest'
) with ( date_rep varchar(200) ) as rows
When don't specify the "with" clause to automatically infer the schema, I have the same problem:
SELECT TOP 10 *
FROM OPENROWSET(​PROVIDER = 'CosmosDB',
CONNECTION = 'Account=analytcstest;Database=ecdc',
OBJECT = 'ecds',
SERVER_CREDENTIAL = 'analytcstest'
) as rows
I could parse it of course, like this, but I don't understand why I have to do that and it's not in the docs?
SELECT TOP 10 JSON_VALUE([date_rep], '$.string') AS [date_rep]
FROM OPENROWSET(​PROVIDER = 'CosmosDB',
CONNECTION = 'Account=analytcstest;Database=ecdc',
OBJECT = 'ecds',
SERVER_CREDENTIAL = 'analytcstest'
) with ( date_rep varchar(200) ) as rows
I tried to reproduce similar thing in my environment and getting similar output A value with data type when I used the CosmosDB for Mongo API:
this can be because of the The Azure Cosmos DB API for MongoDB stores data in a document structure, via BSON format. It is a bin­ary-en­coded seri­al­iz­a­tion of JSON documents. BSON has been extended to add some optional non-JSON-native data types, like dates and binary data.
The Cosmos DB API for MongoDB is meant for MongoDB experience and continue to use your favorite MongoDB drivers, SDKs, and tools by pointing your application to the API for MongoDB account's connection string.
When I tried similar thing with the CosmosDB for SQL API it stores data in Json format, and it is giving appropriate result for that.
For more information on BSON refer this Document

Upgrading to Spring Boot Mongodb 2.2.X hides GeoNear Aggregate pipeline results past 100 records

I have a paginated API backed by an Aggregation with a $geoNear pipeline step.
In Mongo versions before 4.2, $geoNear aggregations had a default limit of 100.
To avoid this, it was possible to set the num field to a large number for the NearQuery.
Query query = new Query();
...
NearQuery nearQuery = NearQuery.near(...);
nearQuery.query(query);
//force the geoNear operation to return more than 100 results
nearQuery.num(Integer.MAX_VALUE);
List<AggregationOperation> steps = Lists.newArrayList(geoNear(nearQuery, "distance"));
//add skip and limit operations to mimic pagination functionality
steps.add(skip(pageable.getPageNumber() * pageable.getPageSize()));
steps.add(limit(pageable.getPageSize()));
Aggregation agg = Aggregation.newAggregation(steps);
...
In Mongo version 4.2, the num field has been removed as well as the limit of 100 results (described here in the first note). In response to this, GeoNearOperation.java has been updated in spring-data-mongodb to remove the num field.
Now, I would understand that if I were to connect to a MongoDb server running version 4.2 everything would work as is (disclaimer: I have not tried this.) However, I'm running version 4.0.5 locally and version 3.6.12 in production. Using spring-boot-starter-data-mongodb with version 2.1.13.RELEASE the above code works and paginated results are returned past 100 results. Upgrading to 2.2.0.RELEASE causes the above Aggregation to no longer return past 100 results.
How am I supposed to query a MongoDB database on a version older than 4.2 with the 2.2.X branch of
spring-data-mongodb if the num field is always removed?
yes try using mongoTemplate. It should work
Point point = new Point(51.4678685, -0.0860632);
List<Pub> venues =
mongoTemplate.find(new Query(Criteria.where("location").near(point).maxDistance(0.01)), Pub.class);
further refer
https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#reference

Tinkerpop path() step equivalent in OrientDB SQL

I have the following working query in Tinkerpop/Gremlin that can return an ordered list of elements traversed until current step.. How can I make a similar one in OrientDB SQL?
g.V().hasLabel('Firma').has('cui','13904073').until(hasLabel('Persoana')).repeat(inE('Actionar').otherV()).sack().path()
I did a similar traverse using MATCH in OrientDB but i can't find a way to get the ordered list of elements traversed:
MATCH{class:Firma,as: FirmaBaza,where:(cui=13904073)}.(inE("Actionar") {as:actEdge}.outV()) {as:act,where:($matched.FirmaBaza!= $currentMatch and #class=="Firma"),while:(true)}.in("Actionar") {as:actPers,where:(#class=="Persoana")} return $pathElements
Is there any way to get the ordered list of traversed elements using OrientDB SQL ?

Cloudant : query in http navigator

I'm using cloudant, with no auth, Cors enabled.
it works very well, Limit and skip working good.
but i can't find how to search for something .
I'm trying to find a document where cp is 24000 , for example with this query :
https://1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/etablissements/_all_docs?skip=0&limit=10&include_docs=true&q=cp:24000
But, the query doesn't return the right document.
I've also tried
https://1c54473b-be6e-42d6-b914-d0ecae937981-bluemix.cloudant.com/etablissements/_all_docs?skip=0&limit=10&include_docs=true&_search({'cp':24000})
with no luck.
oh, and by the way, do you know if jquery.couch.js lib has been discontinued? I cant even find it on github, nor on my hard disk while im using foxant, and it is not in the directory also..
The /db/_all_docs endpoint hits the primary index of the database where all of the documents in the database can be found in _id order.
If you wish to query the database to get a subset of the data you have three options
Cloudant Query - hit the POST /db/_find endpoint passing in a JavaScript object containing the selector which defines the query you wish to perform (like the WHERE clause of a SQL query) e.g. {selector: {cp: 24000}}
MapReduce - create a Map function in a design document that filters the documents you are interested it. It creates a materialized view that can be queried and filtered later. e.g. function(doc){ emit(doc.cp, null);}
Cloudant Search - this uses the Apache Lucene library to generate an index on the fields you specify. You can then query the index: q=cp:24000, which looks similar to the query you are looking to perform.