Firestore query based in subcollection attribute - dart

I have the next structure of content in firestore (a channels collection, and a followers sub-collection in every channel):
channels (is a collection):
- {channel id} (channel document id)
- name,
- description, ...
- followers (subcollection in every channel)
- {user id} (follower document id)
- state (user attribute) = 1 (is active),
I'm trying a query to get all channels of one follower. something similar to:
// dart
db.collection('channels').where('followers.$uid.state', isEqualTo: 1).snapshots();
Where $uid is a valid user id. Then, query result must return all channels where the user is as a follower.
I could do it with an array of user ids in channel, but I'll have a big number of followers and in arrays, I have to read and write complete array in every modification, when I add or remove followers.
Thanks!

The only way to do this is not going to be just a simple query. You can use a collection group query to find all the follower documents among all channels that match some criteria, but you will have to extract the channel IDs out of the paths of those documents using the references in the document snapshots.
db.collectionGroup('followers').where('$uid.state', isEqualTo: 1)
Run that query, then iterate each DocumentSnapshot. Each snapshot will have a reference property that contains the full path of the document. Use the parent property of each reference to work your way up to the DocumentReference that refers to the channel, and add its documentID to a set. After you're done iterating, that set will contain everything you need.

Related

Neo4j Cypher query to fetch posts created by followers

I am creating an app kind of like Facebook. It is an app where people can share products and collections of products. In the "create a post" popup, people can either select a product or a collection (group of products but consider it as a single object) or just text to create a post. I need to fetch the posts created by my followers.
Each post will have a property of type PRODUCT, COLLECTION, OR TEXT to indicate what type of post it is.
In my neo4j DB, there is a Post object, product object, collection object and user object.
When you create a post, relations will be created between them.
(post)-[:CREATED_BY]->(USER)
(post{type:"PRODUCT"})-[:INCLUDES]->(product)
(post{type:"COLLECTION})-[:INCLUDES]->(collection)
This is what I tried to get the posts of type "PRODUCT". IT shows an error. but just to give a basic idea of our properties.
MATCH (user:User{lastName: "mylastname"})-[:FOLLOWS {status: "accepted"}]->(following) WITH following
OPTIONAL MATCH (post:Post {type: "PRODUCT"})-[r:CREATED_BY]->(following) WITH post,user, r OPTIONAL
MATCH
(post)-[:INCLUDES]->(product:Product) WITH COLLECT({post:post, datetime: r.datetime,
type:"PRODUCT",product:product user: following}) as productPosts
UNWIND productPosts AS row
RETURN row
ORDER BY row.datetime DESC
SKIP 0
LIMIT 10
Your WITH clauses are not specifying all the variables that need to be carried forward to the remainder of the query. Also, there has at least one typo (a missing comma).
In fact, your query does not even need any WITH clauses. Nor does it need to COLLECT a list only to immediately UNWIND it.
This query should work better:
MATCH (user:User{lastName: "mylastname"})-[:FOLLOWS {status: "accepted"}]->(following)
OPTIONAL MATCH (post:Post {type: "PRODUCT"})-[r:CREATED_BY]->(following)
OPTIONAL MATCH (post)-[:INCLUDES]->(product:Product)
RETURN {post:post, datetime: r.datetime, type:"PRODUCT", product:product, user: following} AS row
ORDER BY row.datetime DESC
LIMIT 10

Query Firebase Documents with unknown document name in the middle

My Firebase Setup is basically like this:
Collection Users (documents with field: userID) -> Collection wishlists (documents with field: name) -> Collection wünsche
What I would like is query for wünsche but for that I would like to use this code, which is not allowed:
db
.collection("users")
.document(userID)
.collection("wishlists")
.document.whereField("name", isEqualTo: list.name) // <- this is the crucial part which I would like to call but is not possible
.collection("wünsche")
.order(by: "wishCounter")
.getDocuments() {( querySnapshot, error) in }
Is there any workaround for this so I can use .collection after a whereField() ?
Basically: you can't do this, it's not how Firestore Queries work. You can query from a single collection at a time (with the exception of Collection Group Queries).
When you use whereField you're forming a Firestore Query object where you will retrieve a list of Documents in the original Collection.
So this is alone valid Firestore Query object, which you can then call get() on:
db.collection("users").document(userID)
.collection("wishlists").document.whereField("name", isEqualTo: list.name)
You cannot then query Sub-Collections inside that original query, unless you are querying a sub-collection for a specific Document or are performing a Collection Group Query. (It sounds like Collection Group Queries will best fit your use-case, so give the documentation a look).

record field have been truncated when using collect in neo4j

i have data with the structure like below
Node Labeled "GROUP"
GROUP_NAME
politician
worker
game
sports
Node Labeled "MEMBER"
MEMBER_NAME
a
b
Node Labeled "MEMBERGROUP"
MEMBER_NAME|GROUP_NAME
a|politician
a|worker
a|game
b|game
b|sports
Node Labeled "MEMBERLIKES"
MEMBER_NAME|USER_LIKES
a|business
a|lunch
a|rpg
b|rts
b|soccer
then i've wrap it all in node labeled "PROFILE"
GROUP_NAME|USER_NAME|USER_LIKES
politician|a|business
worker|a|lunch
game|a|rpg
game|b|rts
sports|b|soccer
what i would like to achieve are to wrap all those into single row data for each user, like below
GROUP_NAME|USER_NAME|USER_LIKES
politician,worker,game|a|business,lunch,rpg
game,sports|b|rts,soccer
but, when i'm using "COLLECT" statement
match (a:group) where tolower(a.group_name) CONTAINS 'game'
match (b:member)-[:rel_member_likes]->(c:memberlikes)<-[:rel_member_likes]-(d:member)
where NOT EXISTS ((d)<-[:rel_group_member]-(a))
return COLLECT b.group_name , COLLECT b.user_name, COLLECT c.user_likes;
it throw me warning "Record Fields have been truncated" and not all data fetched and show in neo4j browser (actually i have large dataset to collect)
plz help me
Since you are also doing a COLLECT() on b.username, it will not return you a row for each user. If you want to have a row for each user, you should do:
return b.user_name, COLLECT b.group_name , COLLECT c.user_likes;

SSRS: Adding a filter that returns information from entire group

I am trying to create a report in SSRS. Below is a small example of what my dataset looks like.
Example Data Set
So, there are three different stores (A,B,C) and each has a landlord (a,b,c). Landlords can pay via three different methods (1,2,3) and the amounts paid per method are shown.
Right now, I have two filters set up. The first is by Store and the second is by Landlord.
What I am having trouble with is:
How can I set up a filter by the Amount that will return information from an entire Store/Landlord?
So for example, if I wanted to filter Amount by 150, I would like to return all the "payment" information for the store(s) that have a payment of 150. Such as the following:
Desired Result
Is it possible to add a filter to return information from the entire group? (Store and Landlord are the group in this case)
I am new to SSRS so any help/insight would be greatly appreciated!
You can use LookUpSet to locate the matching groups, JOIN to put the results in a string and the INSTR function to filter your results.
=IIF(ISNOTHING(Parameters!AMOUNT.Value) OR INSTR(
Join(LOOKUPSET(Fields!Amount.Value, Fields!Amount.Value, Fields!Store.Value, "DataSet1"), ", ") ,
Fields!Store.Value
) > 0, 1, 0)
This translates to:
If the Store value is found (INSTR > 0) in the list (JOIN) of Stores where the Amount is the current Amount (Lookupset).
In your filter, put the above expression in the Expression, change the type to INTEGER and the Value to 1.
[

Return all users given user chats with and the latest message in conversation

my relationships look like this
A-[:CHATS_WITH]->B - denotes that the user have sent at least 1 mesg to the other user
then messages
A-[:FROM]->message-[:SENT_TO]->B
and vice versa
B-[:FROM]->message-[:SENT_TO]->A
and so on
now i would like to select all users a given user chats with together with the latest message between the two.
for now i have managed to get all messages between two users with this query
MATCH (me:user)-[:CHATS_WITH]->(other:user) WHERE me.nick = 'bazo'
WITH me, other
MATCH me-[:FROM|:SENT_TO]-(m:message)-[:FROM|:SENT_TO]-other
RETURN other,m ORDER BY m.timestamp DESC
how can I return just the latest message for each conversation?
Taking what you already have do you just want to tag LIMIT 1 to the end of the query?
The preferential way in a graph store is to manually manage a linked list to model the interaction stream in which case you'd just select the head or tail of the list. This is because you are playing to the graphs strengths (traversal) rather than reading data out of every Message node.
EDIT - Last message to each distinct contact.
I think you'll have to collect all the messages into an ordered collection and then return the head, but this sounds like it get get very slow if you have many friends/messages.
MATCH (me:user)-[:CHATS_WITH]->(other:user) WHERE me.nick = 'bazo'
WITH me, other
MATCH me-[:FROM|:SENT_TO]-(m:message)-[:FROM|:SENT_TO]-other
WITH other, m
ORDER BY m.timestamp DESC
RETURN other, HEAD(COLLECT(m))
See: Neo Linked Lists and Neo Modelling a Newsfeed.

Resources