Check if field's value already exists in another document Firestore web - Javascript - google-cloud-firestore

I have a collection of 2 documents with fields named 'title'. I would like to know if there is a way for me to catch or check if the title already exists in another document. If I create another document with "TEST1" as the title, it should say " Title already exists".

Related

Create a document that references another document on Firestore collection

I want to create a reference in my collection Masterclasses for users who bought that masterclass. So, the workflow in my code:
User is registering
User is buying that masterclass
Now, I want to add a new document in masterclasses in the new collection called "subscribers" asigned for that user, after purchasing.
The question is, do I have to create the documents with auto generating IDs and add a field userId, then query all the documents and search if my logged in user is equal to that userId, or alternative solution to create the document itself with user id and search by doc id equality?

How to check which feild in mongodb is updated and store that in another feild

suppose there is a db - Profiles , inside that a collection - Managers ,
now in this collection if in one document a field is updated like "current location" which was set to "Mumbai" is changed to "Bangalore".
Then how to catch that which field is updated (here its "current location") and store that name of field in the same document in another field.

Cloud Firestore: check if value exists without knowing field name

I would like to check if a certain value is present in my Cloud Firestore collection through all the present fields and have back the document ID that has at least one field whose value is the one searched.
In this example, the code should give back only 2 records when I look for "Peter": 8cyMJG7uNgVoenA63brG and fnk0kgW7gSBc3EdOYWxD.
I know how to do a search when the field name is known. But in this case, I cannot know the field name at prior.
If you don't know the name of a field, you can't perform any queries against its value. Firestore requires queries to use some index, and indexes always work with the names of fields in your documents.

Remove all fields except one from mongodb document

This Meteor server code needs to remove all fields except "fName" from a document found by a field and if the document does not exist then create it.
Is there a way to do that at one go? thx
myCol.update({fName: someName}, {fName: someName}); // works if doc exists, fails if no doc.
myCol.upsert({fName: someName}, {fName: someName}); // failed if doc exists, works if it exists
You can use fName :{$exists:true} in your query part.
This will update document only if fName in present.

Get a document from couchbase lite database swift

I want to retrieve a document from database to update it, so I need the document ID, how to get this ID if I didn't create the document with a custom ID (I've used database.createDocument() instead of database.documentWithID("docId"))
Thanks
If you haven't created the document with a custom Id then you can use
some other uniquely identifying property (or properties) of the document to query for the specific document.
Instead of querying and iterating over entire list of documents to find the match, you can create a view with the specified property/properties as index. You can then query for that view with startKey / endKey set to the desired property value. That will return the document of interest.
Alternatively,if it's an option, create the document with a custom ID.