Confusion about usage of Aggregate in Parse Server - parse-platform

So I'm trying to get my head around the aggregate function in Parse Server with no luck so far!
Here's what I'm trying to establish:
Say I have a collection named Group, this class contains a list of groups created by users, each record in the group contains a field which is an array of Tag pointers (another collection).
The _User collection also contains an array of pointers named "tags".
What I'm trying to establish, is to get the list of all the groups along with the list of users matching at least one of the tags in the tags array of the Group collection.
I'm pretty sure that this can be done with the aggregate function but I've been trying for hours with no luck!
Any help would be greatly appreciated.
Thanks!

Related

Google Drive API Listing Files with Field Paramter Not Working

I am currently listing some files with the Google Drive API. However, the default list only lists id, name, and mimeType. I know that the fields parameter can list more than just the default, but when I put parents as a field in the Google API Playground, I get the error of Invalid field selection parents. However, when I use * in the fields parameter, it returns all the fields. Am I doing anything wrong by putting parents in the fields parameter? If so, does anyone have any idea how to include the parents field as a field in the list results?
Here is my current endpoint, which causes the error:
https://www.googleapis.com/drive/v3/files?fields=parents&key=[YOUR_API_KEY]
Thanks!
From https://www.googleapis.com/drive/v3/files?fields=parents&key=[YOUR_API_KEY], in your situation, when parents is directly put to fields as follows,
such error of Invalid field selection parents occurs. Because the method of "Files: list" returns the file list which is an array including each file metadata. Ref I think that this is the reason of your issue.
Solution:
So in this case, please set files(parents) instead of parents.
Note:
In the case of files(parents), only parents is returned. When you want to retrieve id, name, mimeType and parents, please use files(id,name,mimeType,parents) to fields.
References:
Try this API of "Files: list"
Files

Categorising documents in elasticsearch

I've got a bunch of ES documents that I'd like to put into "collections". Each document has a unique integer as an ID. Each collection also needs to have a unique integer as an ID.
I need to be able to run queries to get a list of docs in a collection, and easily add an existing doc to a collection.
What would be the most efficient and logical way of approaching this:
An index of collections, which each has an array of document IDs, or
For each document have an array of integers (or a single integer) indicating to which collections it belongs?
Thank you.

In ElasticSearch, how do I get only one from list in subproperties (nested/child/whatever) and sort by it

I have a type Product, which has multiple Prices, but the returned model can only ever have one price.
I need to have multiple prices in elastic, to be able to vary on time without having to reindex. I also need to be able to sort products based on price.
I have tried both with nested and child properties, but I don't seem to be able to query it correctly.
So is it possible to achieve this using elastic? If not, how should I structure my index instead?
You can set the field data type to array. Then sort by for example the max value using the mode option.
See for examples:
https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
What ended up doing is to get the current price via inner hits https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html
And then add the inner hit to the model after it was returned from elastic.

many to many relationship in mongodb

I'm writing a small torrent indexer in Ruby (here) and would love to support MongoDB as an option for the database. Currently, I have the database set up with a many-to-many relationship between tags and torrents.
How would I format a query that gets all the torrent_ids from a map table that match to all the tags in a given list?
I did this in SQL like this:
select torrent_id, count(*) num from tagmap where tag_id in (tag1, tag2, tag3, tag4) group by torrent_id having num = 4"
EDIT: I am right now working only with the collection with torrent_id and tag_id. That's all it has in there. So I'm mapping ids to ids and naught more.
It's better to create a collection to create the mapping consisting tag_id's and torrent_id's. Whenever you add a torrent, also add the torrents tags to the torrenttags collection. Index should be on tag_id.
You can use the following query syntax to get a list of torrents matching more than one tag.
db.tagmap.find({tag_id:{$in: ['tag1','tag2','tag3','tag4']}});
For Aggregation (group by, count) you need to use MapReduce

VB.NET Dictionary.Add method index

When I call mydictionary.Add(key, object), can I guarantee that the object is added to the end of the dictionary in the sense that mydictionary.ElementAt(mydictionary.Count - 1) returns that object? I'm asking because I'm used to Java where HashMap doesn't have any order at all.
I'm hoping to use the ordering given by ElementAt as a way of knowing the order in which objects were added to the dictionary without using a separate data structure.
Update: Looks like ElementAt isn't going to be of any use. Is the best way to do this to use a separate data structure to store the ordering that I need?
Thanks
There is no order to a dictionary. The ElementAt method is a linq extension method that iterates over the dictionary using IEnumerable and counts the number of things, there is no relation to the order things were added.
There is a SortedDictionary, which will sort things by key, but will not keep them in the order they were added in.
If the order is really important you could always have two data structures, a list that you add the object to and a dictionary that stores the key to list index mapping. Or put a field inside your object that set from a counter as you add it to the dictionary.

Resources