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 ?
Related
I'm trying to search a list contained another list with Mongodb.
{_id:1,list:[1,2,3,4]}
{_id:2,list:[1]}
{_id:3,list:[1,3,4,6]}
I' going to search with list of strings. lets say list L =[1,2,3,4,5]
for example with the given list L = [1,2,3,4,5] I want document with _id 1 and 2 to be returned. 3 must not be returned since 6 isn't in L.
I found two solutions
one
two
Since I want to use Spring Data MongoDb Criterias, I tried to write the above solution but the code seems to be not working and it returns all the documents. Any idea how to write this mongo query with spring data mongo Criterias
You can use:
List<Integer> l = List.of(1,2,3,4,5);
Query query = new Query();
query.addCriteria(Criteria.where("list").not().elemMatch(new Criteria().nin(l)));
I am trying to get all the data from GraphDB which starts with certain characters along with ignore case. I am able to write a query that will return me the list which starts with some characters but I am not able to perform any ignore-case operation in that query.
Any help will be appreciated.
Current Query which I am using -
g.V().hasLabel('Product').has('name', TextP.startingwith('Acc'))
Gremlin does not provide the ability to do a case-insensitive search like you want. You will need to normalize your name field (i.e. make it all lower case) prior to saving it to perform this sort of search using the startingWith predicate.
Firstly, the document schema am querying on, is as follows:
{x:10, y:"temp", z:20}
There are multiple other documents in the collection with the same schema as above.
Now, I have a list where each element contains, pair of values belonging to keys x and y. This can be pictured as:
[{10,"temp"}, {20,"temp1"}, .....]
keys -> x y x y
Now, am aware, that if I process the array in a loop and take each pair, I can construct a query like:
query.addCriteria(Criteria.where("x").is(10).and("y").is("temp"))
This will return the document if it matches the AND criteria. I can query with all the pairs in the list in such a manner. But this approach will involve a high number of calls to the data base since for each pair in the list, there is a database call.
To avoid this, Is there any way I can query for all the documents that match this AND criteria for each element in the list, in a single call, using spring data MongoDb Api? Framed differently, I want to avoid looping through the array and making multiple calls, if possible.
You could use Criteria.orOperator to return each Document that match at least one Criteria of your list.
Build your list of Criteria looping over your list
List<Criteria> criteriaList = new ArrayList<>();
for (item : yourList) {
criteriaList.add(Criteria.where("x").is(item.x).and("y").is(item.y));
}
Build your query using orOperator:
Query.query(new Criteria.orOperator(criteriaList.toArray(new Criteria[criteriaList.size()])));
N1QL tutorial for Query has example of how to offset results of the children nodes.
https://query-tutorial.couchbase.com/tutorial/#15
I am trying to write the same query for Couchbase Analytics, but get syntax error.
Goal is to get parent and children starting certain index in children array. For example:
SELECT children[2:array_length(children)]
FROM tutorial
The array slicing syntax is not yet supported in Couchbase Analytics (but it will be soon).
Currently, you can use a nested subquery to get the same result
SELECT (SELECT VALUE c
FROM t.children c
LIMIT array_length(t.children) - 2
OFFSET 2)
FROM tutorial t
I need to apply a set of filters (queries) to a collection. By default, the MongoDB applies AND operator to all queries submitted to find function. Instead of whole AND I need to apply each query sequentially (one by one). That is, I need to run the first-query and get a set of documents, run the second-query to result of first-query, and so on.
Is this Possible?
db.list.find({..q1..}).find({..q2..}).find({..q3..});
Instead Of:
db.list.find({..q1..}, {..q2..}, {..q3..});
Why do I need this?
Bcoz, the second-query needs to apply an aggregate function to result of first-query, instead of applying the aggregate to whole collection.
Yes this is possible in MongoDB. You can write nested queries as per the requirement.Even in my application I created nested MongoDb queries.If you are familiar with SQL syntax then compare this with in of sql syntax:
select cname from table where cid in (select .....)
In the same way you can create nested MongoDB queries on different collections also.