I am trying to write a https cloud function which pulls out specific documents from my cloud firestore. The initial collection is 'Message', however then there are various different sub collections. The path for each document I am trying to view is the following Message/{UserId}/{ChatRoomId}/{UserId_1}. One variable under each UserId_1 is 'creationTime' and I am trying to query for specific documents that satisfy such creationTime. The problem is I don't know how to solve it as I was told this requires the use of collection group queries, which are currently not available in the firestore. Any alternative suggestion?
What I would be trying to achieve in the end is a comparison of each document's creationTime with the current timestamp.
Update: As of May, 2019, Cloud Firestore now supports collection group queries.
As you mentioned, it is not possible at the time of writing to query across collections (the so called "collection group queries" are apparently under development, however).
So the only possibility seems to be a modification of your data model.
You could, for example, duplicate your data and have a collection for each creationTime (probably a Timestamp), under which you have one document for each triplet {UserId}/{ChatRoomId}/{UserId_1}
Related
We have a MongoDB database in a development environment. There are a lot of collections that contain names of people. What we want to do is the following:
mask the names in each collection, the fields need to be updated directly in the database, cannot run them through some external pipeline
once masked, it is ok if we are unable to retrieve the original names (so one-way masking)
every unique name should result in the same mask
the masking script can be run on the mongodb cli or a MongoDB gui like Studio3T
I was thinking of maybe using MD5 or SHA, but I am not sure if either is available to use directly in mongo operations like update or even in javascript without external libraries.
Also, since MD5 always produces the same hash, if someone were to get access to the document, since we will not be masking the field name, it would be fairly easy to feed typical names into the algorithm until the hash matches to figure out the name, but I think we may be able to live with this.
An alternative I was thinking of was, to loop through the unique names we have, and create a map from names to UUIDs. Then, go through each collection and use this map to update the names with the UUIDs. The problem with this is that we'll need to keep this mapping dictionary for when we receive additional documents for an existing person.
Is there any way to be able to only read documents from a query somewhere in the middle of a query instead of just using limit or limitToLast to get one end. Ex; A way to get documents 10-20 categorized by a server timestamp.
No, Firestore doesn't offer any index-based filtering of query results. Those queries do not scale in the way that Firestore requires. Your option for skipping through results is limited to cursor-based queries that let you start at the beginning query results, and paginate through them, as described in the documentation.
I've made a database to store to do lists for different users. For efficiency, I've structured the data so that all the lists and tasks are stored as embedded documents inside each user object. So there's a user, then an embedded array of lists, then in each list an embedded array of tasks. I want my api to prevent duplicate task names in the same list, and duplicate list names for the same user.
I do my filtering operations by name because I don't trust targeting queries with indexes which can change whenever lists/tasks are added/removed, and I don't want to generate a unique ID for each embedded document. I already have duplicate prevention on the front end, but I plan on making this api accessible by other sources and eventually other developers. Is there a reliable way for the api to prevent duplicate names within those scopes?
I've heard it can be done with mongoose schemas, but I haven't seen any examples that are specific enough for my issue. All I've been using is mongoDB shell so I'd rather not switch everything to work with mongoose schemas unless it's going to be very beneficial overall.
I am having troubles with firebase using the cloudstore .where query.
I want to query a big collection of documents (in my case posts) but I only want to query the posts in which the groupId matches any of the groups that the user is in. The reason for this is that I want to query a combined feed for the user with all the latest relevant data (using orderBy and limit).
I know that I can use array-contains, so I could for instance query all of the posts for user where the user is a member.
firebase.db.collection('posts').where('members','array-contains',firebase.uid)
This would work if I decided to keep track of the members in a group. Problem is if I would change members in a group, I would have to loop through all posts and change the array of members (not really good practice). Better would then be to have the post contain and id of which group it was posted in.
So let's say the user has an array containing all the groups he is in
user.groups = ['companyGroup', '{id}', '{id2}']
I would then like to query through the whole posts collection and get all the documents where the field groupId matches any of the values in user.groups something like this:
firebase.db.collection('posts').where('groupId','==',[any of user.groups])
or maybe the reverse:
firebase.db.collection('posts').where(user.groups,'array-contains','groupId')
^ I have not tried this one but I am certain it doesn't work according to the docs according to
The where() method takes three parameters: a field to filter on, a comparison operation, and a value. The comparison can be <, <=, ==, >, >=, or array_contains.
Is there a possible way to do something like this? I can't really query multiple locations at once and combine them because that defeats the purpose of being able to limit the data and orderBy fields. I understand that I could put a new collection called feed under every user and for every post use a firebase function that pushes to post to the relevant members feed (only the id and latestActivity), but then as soon as that post changes (I am going to use a field called latestActivity to order data according to relevancy, but also when deleting a post) I would need to loop through all docs under every user affected and change the value/delete doc.
Any ideas are greatly appreciated!
Currently, there is no way to pass an array of ids to the where() function and expect to get all the documents that corresponde to each particular id:
firebase.db.collection('posts').where('groupId','==',[any of user.groups])
The option that you have, is to store in the array either the ids as strings or references (path to group documents). There is no real advantage of storing references rather than strings, so it's up to you to decide which one you feel more comfortable with.
To get the all group documents, you should get the array that contains those ids/references and for each one separately create a new database request. So unfortunately there is no other way to get those group documents at once using a single query.
However, creating extra database calls it doesn't mean that fetching, let's say 3 documents, will be 3x slower as fetching one document. You can make some tests yourself.
I quote #Frank van Puffelen, "Firebase has a history of performing fine in such cases, since it pipelines the requests."
use array contain it works perfectly.
firebase.db.collection('posts').where(user.groups,'array-contains','groupId')
it works pretty good for me . you should try this.
In Adobe campaign I have several (400+) schemas so I need to query all of them to see if they have recent data so that I will know what schemas need to monitor. To do this I will use the creation date on every schema. The problem is that I don't want to do it manually (go 1 by 1), is there a way to automate this and get all the schemas let's say using java script and then use a query with the creation date and pass a specific date ?
Though it is possible, you may avoid it and try to consider as #theopendle mention, a database level query.
Nevertheless, just use the Source schema (xtk:srcSchema) and you will have all the schemas listed. Then you can use that retrieved schema in your next "monitoring" process.
This answer assumes you are using Adobe Campaign Classic (on premise) not Standard (cloud versions):
As far as I know, there is no way to easily do this from within Campaign. However, all the schemas you can query using the Generic Query Editor or in a worflow correspond to tables in the Oracle database on which AC is based. If you connect to this database you can run regular Oracle SQL queries which gives you much more control.