Unable to query firestore collection on timestamp column - google-cloud-firestore

I have a Firestore database which contains a list of jobs in a "jobs" collection. Each job has an end date which is a "timestamp" data type. When I try to query using a where condition, I get no data back when using the react-native-firebase module.
Snapshot of data
Below is the code I'm using:
return db.collection('jobs')
.where('end', '>=', new Date());
Also tried:
.where('end', '>=', new Date().toISOString());
Is there a specific data type/format I must send the date value as for it to match?
When I use the standard web SDK from Firebase on my web app, the data comes back correctly.

We had an issue with date conversion going across the React Native bridge, we've since fixed this and the fix will be part of the v3.1.0 release in the next day or so.
An example of date querying can be seen in our tests: https://github.com/invertase/react-native-firebase/blob/master/tests/src/tests/firestore/collectionReferenceTests.js#L523
So you are querying correctly with .where('end', '>=', new Date());
Thanks

Related

Filter results on the Firestore console by timestamp field

How can I filter the results on the Firestore Console by a timestamp field?
On the collection users, we have a field createdOn of type timestamp. If I want to filter the collection by field, I get the following dialog
I have tried entering the date as string
2019-09-15
2019-09-15T00:00:00Z
I have also tried using a timestamp as number in millis and seconds
1568505600000
1568505600
When looking at the requests sent to Firestore, the structured query uses a field filter with a value of corresponding to either stringValue or integerValue, but I think the timestampValue would be the right thing.
I do not want to adapt the query in the console and build my own requests. I know that there is always the option to sort the documents in the collection and then scroll to where it's interesting, but this will load all documents that are not relevant.
Is there a simple way to do what I want?
There is a new query builder tab in the console (I do not know when this was introduced, but I assume during the Firebase Summit 2022). For the query above, this would look like this
It even has a timestamp type in the select list.

Meteor JS : How to get latest set of data based on the date?

I have a requirement where my db has say some set of records with same timestamp (latest) and i want to get all of them at once, i don't want to get any other data which doesn't belong to that criteria, problem is i will not know the timestamp because it stored in db from outside world.
How do i get only the latest set of data in meteor ? i cant do findOne, as it will bring only 1 latest record, which is wrong in my case.
Meteor.publish("collection1", function() {
return Collection1.find({}, {sort:{dateTime: -1}});
});
I tried to do above code but it gets all the record and i think it just sort by desc.
Use the findOne() method to get the latest dateTime value that you can then use as the find() query:
// on the server
Meteor.publish("collection1", function() {
var latest = Collection1.findOne({}, {"sort":{"dateTime": -1}}).dateTime;
return Collection1.find({"dateTime": latest});
});
// on the client
Meteor.subscribe("collection1");
Collection1.find().fetch();
The above approach makes your Meteor app scalable client-side as the client only subscribes to the data that you only need. This is made possible because the return statement inside the Meteor.publish function can only return documents that have the latest dateTime value. This way, you'll avoid overloading the browser's memory no matter how big your server-side database is.

How to send HTTP request to sails.js + MongoDB with createdAt parameter?

I am trying to post a query to Sails.js via HTTP POST in order to find records created after a certain point in time.
Using the following syntax works perfectly and gives me back one record with the correct time:
localhost:1337/object?where={"createdAt":"2014-08-19T14:36:16.047Z"}
When trying to add an operator the query does not work any longer giving me no records in the object collection :
localhost:1337/object?where={"createdAt":{">":"2014-08-19T14:36:16.047Z"}}
Due to the fact that the date conversion from ISODate to dateTime works for the exact query I suppose it should also work for the ">" query.
Highly appreciate some help on this one.

get day of the week from mongodb datetime query

I am constructing a database where I might want to query a day of the week. Is it possible to use mongodb to query days in the week in a datetime (or utc timestamp) field?
Something like; get every object that has a datetime that was on a monday.
If it is not possible then the alternative seems to create dummy variables in the collection that show what day of the week it was. Preferably I would like to only query the datetime object for this as this would keep the database smaller.
There are three solutions that I can think of:
Your solution: create an extra "day_of_week" field, either an int or string, and then query against this field rather than the datetime field.
Query for everything in your collection, and then filter the results by day of the week on the client side.
Use $where, passing a javascript function which calls date.getDay(). For example, {$where: function () { return this.date.getDay() == 5; }} for getting every date on a Friday.
Solution #2 would call datetime.date.weekday() in pymongo on the client side. The downside of this method is that every document in the collection will end up being sent over the wire, which could add unnecessary network load. It's better than #1, however, in that it's more space efficient and you don't have duplicated information to keep in sync. Solution #3 has neither of these problems, but $where is slow because it requires the server to create a JavaScript execution context and cannot make use of indexes.
Pymongo can return Mongo BSON timestamp fields as python datetimes: http://api.mongodb.org/python/current/api/bson/timestamp.html
From there you can call datetime.date.weekday()
http://docs.python.org/2/library/datetime.html#datetime.date

how to embed another timestamp but not now to mongoid

I have activities that I should add to mongodb, activities have, dates and times, I should sort them, What I want, is not to have another field for timestamp and index that field also, I don't want the time when the document is created, I want to embed that activitie's timestamp to mongoid, I searched and tried this one but did not work,
"_id" => new MongoId($stamp)
Is there a chance, that I can embed future timestamp to mongoid ? thank you :)
It is possible, but not directly through the driver. I have written an example at Create MongoDB ObjectID from date in the past using PHP driver that shows you how to do this.