I have to add a condition if the order saves is called using async bulk API only.
so, how to know if the order save function is called using the bulk async API process?
Related
I'm wondering if there is a way to bulk update documents in firestore via the Firestore console. I'm aware that I am able to do this via code, as shown in answers such as this one and this one, but I'm mainly looking for a way to do this via the Firestore console/UI.
At the moment, I am able to update one document at a time, but is there a way for me to update all documnts (matching a filter for example) at the same time to have the same update?:
I find that I often want to do this when I'm prototyping, and having to write code just to do a bulk update adds additional time to something I would think would be simple to do via the UI. I'm currently on the free spark plan, so I also can't use cloud-functions, meaning I have to spin up a server to do the bulk update via the admin SDK. Is there a way to bulk update documents via the firestore console or some other UI?
Currently Cloud firestore supports editing single documents via console. but not in bulk. The only way to edit documents in bulk is either using Batch writes or Transactions. If it is necessary for you to use console, you can raise feature request here
I have webhooks being sent to firebase functions for when Products, Customers, Orders, and Subscriptions are created, updated, restored, and deleted on my WooCommerce site. I am using one destination URL for all of the webhooks (16 - CRUD for Orders, Products, Customers, Subscriptions) and then they are parsed and handled in Firebase functions.
Is this single destination URL a best practice, or should I be creating a new destination URL for every webhook or even every webhook category?
I could see creating a separate one for orders vs products but creating 4 separated ones for product-update, product-create, product-restore, product-delete seems like overkill.
You have the ability to go with creating an express app in NodeJS for example, and for your https trigger.onRequest method, pass in your express app, and let the functions handle it from there. It keeps your code cleaner, easier to maintain. For now you are using the web-hooks you mentioned, but if in the future, modifying your express app, would be easier than creating a new cloud function.
You probably have read these docs, but just in case, leaving them here.
In the end, billing would be the same, because you are charged per invocation. Using an app would be cleaner.
Firebase Firestore: How to monitor read document count by collection?
So first of something similar like question was already asked almost a year ago so dont mark it duplicate cause I need some suggestions in detail.
So here is the scenario,
lets say I have some collections of database and in future I might need to perform some ML on the DB. According to the documents visit.
That is how many times a specific document is visited and for how much time.
I know the mentioned solution above indirectly suggests to perform a read followed by write operation to the database to append the read count every time I visit the database. But it seems this needs to be done from client side
Now if you see, lets say I have some documents and client is only allowed to read the document and not given with access for writing or updating. In this case either I will have to maintain a separate collection specifically to maintain the count, which is of course from client side or else I will have to expose a specific field in the parent document (actual documents from where I am showing the data to clients) to be write enabled and rest remaining field protected.
But fecthing this data from client side sounds an alarm for lot of things and parameters cause I want to collect this data even if the client is not authenticated.
I saw the documentation of cloud functions and it seems there is not trigger function which works as a watch dog for listening if the document is being fetched.
So I want some suggestions on how can we perform this in GCP by creating own custom trigger or hook in a server.
Just a head start will be so usefull.
You cannot keep track of read counts if you are using the Client SDKs. You would have to fetch data from Firestore with some secure env in the middle (Cloud Functions or your own server).
A callable function like this may be useful:
// Returns data for the path passed in data obj
exports.getData = functions.https.onCall(async (data, context) => {
const snapshot = admin.firestore().doc(data.path).get()
//Increment the read count
await admin.firestore().collection("uesrs").doc(context.auth.uid).update({
reads: admin.firestore.FieldValue.increment(1)
})
return snapshot.data()
});
Do note that you are using Firebase Admin SDK in this case which has complete access to all Firebase resources (bypasses all security rules). So you'll need to authorize the user yourself. You can get UID of user calling the function like this: context.auth.uid and then maybe some simple if-else logic will help.
One solution would be to use a Cloud Function in order to read or write from/to Firestore instead of directly interacting with Firestore from you front-end (with one of the Client SDKs).
This way you can keep one or more counters of the number of reads as well as calculate and apply specific access rights and everything is done in the back-end, not in the front-end. With a Callable Cloud Function you can get the user ID of authenticated users out of the box.
Note that by going through a Cloud Function you will loose some advantages of the Client SDKs, for example the ability to use a listener for real-time updates or the possibility to declare access rights through standard security rules. The following article covers the advantages and drawbacks of such approach.
I have setup Analytics Export to BigQuery. Everytime when a new ga_sessions_yyyymmdd gets created I would like to run some queries aggregating some data for future use.
I can't figure out how to do this. Do I have to create a job and trigger it from outside or is there a way to trigger this in BigQuery directly (prefably using the Web UI).
You cannot schedule queries to run via the Web UI. You'll need to write a small piece of software to do this by using use the BigQuery API, and cron(s).
You may also want to check out Cloud Functions - bearing in mind that it's still in Alpha.
I am thinking about a system which includes XML or XML-like tech. My scenario, i have products in my database tables and i want to export these products, so any user can get my product list with an XML or another way and import their system. It is common usage, i know but i wonder, how can i sync the product quantities. What will be happen, if any user sell my product. How can i edit the quantity field in my DB ? Which technologies can i use ? I think API will be best but how can i use XML ?
You need to create a public api.
users should create an account and you give them an api-key in order to access the api.
you give them a GET method with they use to recieve the product list and a POST method to report the purchases. Once the purchase comes in from the user, you update the records accordingly in your database.
MVC 4 has some good capabilities to create api.
See below:
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
How to return Xml Data from a Web API Method?
Creating REST API for existing MVC based website