How do I check if an edge exists between two collections in ArangoDB AQL? - arangodb

I would like to ask if there is a way in ArangoDB AQL to see whether an edge exists between two collections?
At the moment I have a collection called staff and one called department
Basically for the query I need to check if and edge exists between them and then sort them by if they have and edge or not.
FOR s IN staff
// do something here to check if edge exists and then sort
RETURN s
Any help would be appreciated!

Related

Can I search a vertex from a graph in using _key and dont know the collection name?

I have a problem when do a traversal for a graph.I think the ArangoDB java driver dont support to find a vertex in using _key.And this like the janusgraph "g.V().has('xxxx','yyy')".
Or can find a vertex from a graph in using _key?And how?
Thanks
Probably the SEARCH option is a solution:
filter documents based on AQL Boolean expressions and functions
match documents located in different collections backed by a fast index
sort the result set based on how closely each document matched the search conditions
more info you can find here: https://www.arangodb.com/docs/stable/aql/operations-search.html

Firebase Firestore query by subcolletion length

I am trying to query my Firestore collection (in Node.js for my flutter app), and to get the 10 documents which has the most objects in their subcolllection called Purchases (to get the best sellers).
Is it possible in Firestore? Or do I have to keep an int field outside of my subcollection to represent its length?
Thank you!
I thought this was answered recently, but can't find it right now, so...
Firestore queries (and other read operations) work on a single collection, or a group of collections with the same name. They don't consider any data in other (nested or otherwise) collections, nor can they query based on aggregates (such as the number of documents), unless those aggregates are stored in a document in the queried collection.
So the solution is indeed to keep a counter in a document in the collection you are querying against, and updating that counter with every add/delete to the subcollection.

Connecting one document to multiple documents in arangodb

Am fairly new to Arangodb and am trying to find an example where if you are given one user{} and a list of [user{}] how can you create multiple friend edges from that one user{} to the list of [user{}] in one go. I read the documentation and there is an example for a single edge creation
graph.edgeCollectionName.save(from, to, data, options)
and am thinking of running a for loop but I have a feeling that the mutations are not batched. What would be the best way to do this?

What NoSQL database could accommodate the following data structure?

I want to create a database of events. Events by the same user would have the same user id. I could then execute queries to retrieve users who had done events A and B but not C.
I've had a look at Cassandra but I'm unclear about how I should model this data.
The approach I thought of would be:
Every entry in the database gets a unique id (because I think Cassandra requires a unique primary key?), and then I have one column which is my user id, non-unique. Then I am free to give each event other columns, depending on what is relevant to that event. So I might have some entries:
1,user1,event_column=registered,fname_column=James,lname_column=Mason
2,user2,event_column=deleted
3,user1,event_column=pageview,page_column=homepage
and so on.
Then I'm a bit unclear about how I would select users who had done A and B but not C. Could I do that with one query? Or would I need to bring into java all users who had done A, then all users who had done B and filter for users in common?
Does that approach sound possible and a good way to use Cassandra?
Are there other open source distributed databases which might be appropriate?
Thanks for your help!
With a secondary index on the "event_column" you can ask ...WHERE event_column IN ('A', 'B'), but you cannot do a NOT IN clause like in conventional SQL. (See also this answer).
An example of a database that supports your query is MongoDB where $nin and $in are similar to NOT IN (...) and IN (...), respectively. (MongoDB is a document database where Cassandra is a column database.)
In order to prevent a complete scan of all documents, remember to put a secondary index on the events property if only a minority of documents will contain the events that you search for.

How to find all documents in a database created by many different users?

I need to find all documents in a database which have been created by x number of users and the result must be a combined (sorted by date) list/collection of documents from all these users.
so I have a multivalue field that contain e.g 100 users, I now need to return a collection programmatically with all the documents in the database that has been created with those users.
worth mentioning here is that the 100 users is dynamic, so in another document there might be 100 different users that is the be used for the search.
I have experimented with the following kind of query, but I believe I run into some kind of limit in the search query. (looks like if the query is to long I get query is not understandable)
FIELD CreatedBy Contains "Thomas" OR FIELD CreatedBy Contains "Peter".... up to 100 more like this
also, finding these documents is triggered by webusers so it must be relative fast.
is there another way to find these documents?
Thanks
Thomas
Your best bet might be a view sorted by the creator and a loop with 100 getAllDocumentsByKey. You could run a comparison if you sort the entry field and just walk through the viewnavigator after jumping to the first document.
The result could be added to a folder (you need to manage folders for different query sets and have a cleanup routine) that is sorted how you need it or you sort in memory (think JavaBean). The folder option makes paging to the result easier - you probably don't want to show 10000 results in one go - that would take very long to transmit. You also could use a "result document" where you store the result as JSON and use that as paging source.
Easily done with Ytria's ScanEZ. They have trials, I think

Resources