Overwrite vs merge difference in Firebase - google-cloud-firestore

From reading the documentation for the set document operation, it seems to me that overwrite and merge mean the same thing which is to replace existing data with new ones. I'm not understanding the difference between the two, even they are phrased to have separate meanings here.
Specifically where it says
If the document does exist, its contents will be overwritten with the newly provided data, unless you specify that the data should be merged into the existing document, as follows:

.set(), by default will OVERWRITE any existing document, and will create a document if it does not exist. By default, if you do NOT specify a field in your data, the existing data in that field will be DELETED - the incoming data will become the new DOCUMENT, and all previous fields/data will be lost.
.set() can OPTIONALLY be provided with an object, one field of which is "merge". IF this field exists, and IF it is set to true, the ONLY fields specified in the new data object will be added and/or overwritten. Remember that Firestore documents are effectively Maps, and fieldnames must be unique. New fields will be added; existing fields will be overwritten; fields that are NOT present in the data object will remain - hence "merge".
.update() REQUIRES that the document ALREADY exist, and will fail if it does not. By default, it will ONLY write to the fields specified as arguments to .update()

A set-and-merge will create the document if it doesn't exist, where an update call will fail in that scenario.
There may be more differences that I'm not aware of, but this is my main reason for picking one over the other.

Related

Marklogic DHF5:- Can we return multiple content for one document in main.sjs

We are migrating from MarkLogic DHF4 to DHF5 (Data Hub Framework)
We are having scenario where for one entity, depending on criteria we need to create more than one harmonize document for a single input document. This scenario was possible in legacy flow where we used to call write:write method.
But in DHF5 implementation we are supposed to return only one content for one input document getting processed in main module main.sjs.
Is there a way where we can create multiple harmonize document as required from one input document in DHF5?
We expect that one input document should be able to create more than one harmonized document in single step(in main.sjs)
Your custom module is expected to return a Content object or an array of them. Each Content object must have uri, value, and context properties and may also specify provenance.
Based on this, your one input can be turned into multiple outputs.
See the "Required Outputs" section on this page for more details.
Your module must return the following:
For a Custom-Ingestion step, a Content object.
For all other custom steps, a Content object or an array of Content objects.

Firestore Security rule always returns null for resource

I am trying to create some firestore security rules. However, every rule that I write that involves something other than the users database pulling the document of the current user results in an error. There is some difference I am missing.
Here is the query and the data. The resource object is always null. Any get function that involves pulling from the design database using the designId variable also results in null.
You're putting a pattern into the form, which is not valid. You need to provide the specific document that you want to simulate a read or write. This means you need to copy the ID of the document into that field. It should be something like "/designs/j8R...Lkh", except you provide the actual value.

Firestore security rules based on individual documents?

In my Google Firestore collection, I have a series of documents. Each of these documents have their own data. Included in each of these documents is a field called api_key;
Using Javascript, how would I make it so that a set/update command can only be accepted if the command properly includes the value in api_key. Using the api_key, the script should be able to set/update any content within that document tree... and only that document tree.
Is something like this possible?
I don't believe this is possible currently (without using a deprecated expression, which is strongly discouraged), because security rules don't allow you to distinguish between a value provided for a field in a document update, and the value of an existing field with the same name. It's tempting to try this to try to compare the provided value with the existing value:
allow update: if "apiKey" in request.resource.data
&& request.resource.data.apiKey == resource.data.apiKey;
But when you say request.resource.data.apiKey, that will evaluate to either the existing field value in the document, or the provided value. So, if someone simply didn't provide apiKey in the update, the security rule would just provide the existing apiKey value, and the write would be allowed. This rule would just reject writes where the apiKey is provided by doesn't match the existing value.

Document versus Dynamic Document Property

What is the key difference between Document and Dynamic Document Property?
We were trying to use these properties in Boomi atomsphere process development but not able to decide which is the best to use.
Document properties: - are additional information or "metadata" about an individual document as it executes through a process. The values contained in properties are separate from the document's actual data contents. These properties remain with a given document as it progresses through the various process steps, even as the document data itself is manipulated through Map steps or outbound connector calls.
There are two types of document properties:
standard document properties :contain run-time specific information such as connector or trading partner details.
Dynamic document properties : are arbitrary values that you can use to temporarily store related values.
Document Properties: Document properties are additional information or "metadata" about an individual document as it executes through a process.
Usage: I have used document properties of Disk, FTP, SFTP for creating file names. Also document properties of Mail can be used to create Body, filename, subject, from Address and To Address.
Dynamic Document Properties: Dynamic document properties are properties that the process developer can define and use to temporarily store additional pieces of information about a given document.
Usage: I have used this to create an ALL_INDEX to get all the data from data cache

Determine which Mongo collection an document exists in?

Is there a way in Meteor/MongoDB to do a find to get the collection an document's _id exists in?
What I am trying to accomplish is to create a generic Comments framework for my app, where comments can be applied to several different document types that are saved in multiple Mongo collections. For instance, comments can be applied to Pages as well as Comments. What I need to do is save the comment, then modify the parent document. I can pass in the _id of the parent, but without strong typing I can't figure out if this is a Page or a Comment (or any other "commentable" type I might come up with.
One solution, I think, would be to store the "parent"'s ID in the comment, but I wanted to try to save an array of comments in the parent instead.