How to get documents in Google firestore by created\updated date.? [duplicate] - google-cloud-firestore

This question already has answers here:
How can I query firestore by document snapshot updateTime?
(3 answers)
Closed 2 years ago.
i want to get only the documents that are newly created and\or updated in my collections\sub collections.
i see we have a create_date , update_date metadata methods on the document object (using python SDK).
can we use it and how.? or is there any better ways i can do it easier.
Regards,
Sai

There is no way to query Firestore by this metadata. If you need to use such timestamps in your queries, you'll need to add them to your documents as regular fields, typically setting them as server-side timestamps (to prevent clients from tampering with them).
Also see: How can I query firestore by document snapshot updateTime?, which I'll mark your question as a duplicate of now that I found it.

Related

How to pull collectionGroups in Flutter Firestore? [duplicate]

This question already has answers here:
How to list all subcollections of a Firestore document?
(1 answer)
How to list subcollections in a Cloud Firestore document
(4 answers)
Closed 11 months ago.
Here's a build:
Here I want to pull all the collections inside the document. How can I do that?
I tried a code like this:
FirebaseFirestore.instance.collection("users").doc(user.uid).collection("Mission1").get().then((value) {
value.docs.forEach((doc) {
print(doc.data()["title"].toString());
});
});
But in this code, I need to enter the collection name. Before I go in, I want to pull all collections.
Thanks in advance for your help.
that's undoable in firebase according to the documentation:
Retrieving a list of collections is not possible with the mobile/web
client libraries. You should only look up collection names as part of
administrative tasks in trusted server environments. If you find that
you need this capability in the mobile/web client libraries, consider
restructuring your data so that subcollection names are predictable.
https://firebase.google.com/docs/firestore/query-data/get-data#list_subcollections_of_a_document
you should build your data structure in way that doesn't need this requirement, although you can make some solutions like storing all subcollections names inside your doc, but that wouldn't be efficient in real-life applications.

How to sort cloud firestore documents inside the database? [duplicate]

This question already has answers here:
How can I order the documents in Firestore?
(2 answers)
Closed 2 years ago.
I am using Cloud Firestore as my dataBase.
Getting my wanted data from the database to the client-side and sort it was no problem at all.
If I want to visually numerically sort the documents that are inside the database how can I do it?
Example:
For example, take a look at database that looks like this:
what I want is to sort those documents numerically so it would look like this (5 <= 10 <= 15):
In the Firestore console, documents and collections are always sorted lexicographically. by ID. This behavior can't be changed.
Your only alternative here is to change the IDs so that they would sort in using the natural sort order of strings. This means they would have to be named using a scheme like "0001", "0002", "0003", and so on. This is probably not worthwhile, unless the console is the primary way you deal with data in Firestore (and if that's the case, you probably shouldn't be using Firestore).

What does it mean to say that MongoDB is atomic on its level of write operations? [duplicate]

This question already has answers here:
What does "atomic" mean in programming?
(7 answers)
Closed 5 years ago.
I'm reading MongoDB's documentation but not seeing an actual definition of what they mean by "atomic". Can somebody help explain this, please?
It refers to multiple clients simultaneously updating the same record.
When two clients write to the same document, they will not mix the content, only one of them will update the document, so you will not have some fields from one client and other fields from another client.

slow Meteor fetch after quick find [duplicate]

This question already has answers here:
MongoDB Fetching documents slow (Indexing used)
(2 answers)
Closed 3 years ago.
We are using Kadira to try to determine why our Meteor application is running slow at times. You can see in the picture that the find operation is fast while fetch took almost 7s. I know it's an open question but does any have an idea of what could be causing this?
The find command will return a cursor, which is a pointer to objects in database while the fetch will return an array with all the objects directly to your browser.
It seems you are retrieving a lot of objects since 6 seconds is a lot of time. I will suggest you to check if you really need to fetch too many objects, since maybe the user will not see all the data in just one screen.
Maybe you have already the data in your local MongoDB, and you can query them by chunks. (Using the limit constraint in MongoDB).

Elasticsearch and NoSql database [duplicate]

This question already has answers here:
Elasticsearch as a database? [closed]
(4 answers)
Closed 8 years ago.
What is the use to use both ElasticSearch and a separated Nosql database ?
Can't Elasticsearch be used both as a database and for search indexing ?
Yes, you can use ElasticSearch as a data source as well as an index.
By default each document you send to the ElasticSearch system is index, and, the original document is stored as well. This means whenever you query ElasticSearch you can also retrieve the original JSON document that you indexed.
If you have large documents and you want to be able to retrieve a smaller amount of data then when you can use the mapping API to set "store" to "yes" for specific fields, and then use the "fields" key to pull out specific fields you might want.
In my system I have address autocompletion and I only fetch the address field of a property. Here is an example from my system:
_search?q=FullAddress:main&fields:FullAddress
Then when a user selects the address I pull up the entire JSON document (along with others).
Note:
You cannot do updates like you can in SQL (update all items matching a query to increase an attribute, let's say)
You can, however, add a new document and replace the existing one at the ID you want to update. Elastic search increments a _version property on each document which can be used by the developer to enforce optimistic concurrency, but it does not maintain a separate version history of each document. You can only retrieve the latest version of a document.