How to query on firestore where field contains array of dictionary? - ios

I am trying to fetch project data from FireStore and here is my structure on firestore:
And here is my code:
FirestoreReferenceManager.rootProjects.whereField(
FirebaseKeys.ProjectDetails.inviteData,
arrayContains: [
FirebaseKeys.ProjectDetails.otherUserId: userID,
FirebaseKeys.ProjectDetails.inviteStatus: FirebaseKeys.ProjectDetails.pending
])
If I don't have isInvoiceAccess data on firestore then above code is working fine but when I add that key on firestore then above query is not giving me any results and I can not add that key because it can be true or false.
If I use below code then I am getting the results:
FirestoreReferenceManager.rootProjects.whereField(
FirebaseKeys.ProjectDetails.inviteData,
arrayContains: [
FirebaseKeys.ProjectDetails.otherUserId: userID,
FirebaseKeys.ProjectDetails.inviteStatus: FirebaseKeys.ProjectDetails.pending,
FirebaseKeys.ProjectDetails.invoiceAccess: true
])
So I want data from FireStore without adding isInvoiceAccess in my query.

The arrayContains operation only checks whether there is exact match in the array, it cannot check for partial matches.
The common workaround for your use-case is to add an additional array field for each specific values/combination of values that you want to query on. So in your case, add a field invites_uid_and_status with just those two values for each, and then use that for this query.

Related

PowerAutomate : Get max columnvalue From dataverse table

I have a Dataverse table named my_sample_table.
Inside the table I have a column named my_sample_column of type integer whose max value should be returned. Am trying to achieve this by using the List rows action provided with PowerAutomate.
Is there a filter query that can be written on the Filter rows property ? similar to what we use with SQL : max(columnname)
Or any other queries that can be included in the List rows action which will return the same result.
I know that I can iterate through the column values to get the max value using an expresion or by sorting it and getting the topmost one. But I was wondering whether there are any direct approach to it.
I would try and use a max aggregate for this column in a Fetch Xml query:
https://learn.microsoft.com/en-us/power-apps/developer/data-platform/use-fetchxml-aggregation#max

To store collectons of collections in neo4j

I will like to store a collection of collection in the neo4j, but it is giving me an error so is there any other way.
Query:
CREATE (d:Dummy {property:[null,null,null,[23,32,23],null,null,[23,23,23]}) RETURN d
Error: Collections containing null values can not be stored in properties.
So how to solve this
Thanks
Your collection violates at least these 2 neo4j constraints:
Properties cannot store collections containing null values.
Properties cannot store collections with nested collections.
If you really need to store such collections, one workaround is to store the collection in stringified JSON format. For example:
CREATE (d:Dummy {property: '[null,null,null,[23,32,23],null,null,[23,23,23]]' })
RETURN d
Later on, when you need to use the property value, you will need to convert it back to a neo4j collection. The apoc.convert.fromJsonList function can be used for that purpose. For example:
MATCH (d:Dummy)
RETURN apoc.convert.fromJsonList(d.property);

Sorting a List in Realm Swift

I have a List of objects, which I need to sort by a date property. I'm using that list to display the items in a UITableView
My problem is that, sorting a List in Realm returns a Results<myItem> instead of a List<myItem> object.
What is the proper way to sort a List in Realm without converting it into a Results object?
Workaround can be:
add extra field like timestamp of your date property (in millis), everytime you insert a record. (not required if you are sorting data based on data field)
sort query data = data!.sorted(byKeyPath: "date", ascending: false) for more options
Realm query will return RLMResult only.for unmanaged object

Swift - Core Data group by date when pulling another attribute

I have the following Entity model (name and data type) in Core Data:
Item - String
Timestamp - Date
Value - Double
Is there any way to fetch the equivalent of "select date(timestamp) as date_value, sum(value) from Entity group by date_value, value"?
Googling on groupings doesn't explain how to do this with the Date type very clearly. I tried a workaround by adding a new column called date_string where it's a formatted String version of the Timestamp column, like '2018-03-19', but it doesn't seem very elegant and doesn't really work.
You don’t do this while fetching when using Core Data but rather fetch all relevant objects and then do the grouping and summation in your code.
I would use a dictionary with dictionaries for this, date (as string) as key and double as value for the inner dictionary and the item property as key and the inner dictionary as value for the outer dictionary. Or alternatively create a summation structure and use that in a single dictionary.

Isn't it possible to query Firebase Database children(not keys) in combination of queryStartinAtValue and queryEndingAtValue?

I want to query my data such that I get the objects whose timeStamps are in the range of my desired timeStamps.
My JSON data is:
"-KHbFGKIyefgWKEmlkY1" : {
"createdAt" : 1463094941,
"customer" : "user1",
"professional" : "professional1",
"service" : "service2",
"startsAt" : 1470070000,
"status" : "WaitingForApproval"
}
My code to make the query:
let minimumDesiredTimeStamp = 1470000000
let maximumDesiredTimeStamp = 1480000000
ref.queryOrderedByChild("startsAt")
.queryStartingAtValue(minimumDesiredTimeStamp)
.queryEndingAtValue(maximumDesiredTimeStamp)
.observeSingleEventOfType(.Value, withBlock: { (snapshotOfChildrenWhichStartsAtTimeStampRange) in
})
The problem is that query never jumps in the closure.
If it's not possible with current Firebase , can you suggest a way on how to achieve this?
NOTE: For now, I've solved the problem by querying with only combining queryOrderedByChild and queryStartingAtValue and then filtering the objects whose start time exceeds my range, with the help of Swift arrays' filter method.
NOTE2: When I tried the code again with hard coded values, I realised that the query really works. So it seems I've misidentified the problem and something else causing the query not jumping in the closure.
So remember: querying child values in combination of queryOrderedByChild.queryStartingAtValue.queryEndingAtValue works!

Resources