I want to delete all documents created between the dates 2017-08-18 and 2017-08-22. I was told that all documents have CosmosDB's own timestamp under the field '_ts'. I tried using the document explorer to filter the documents using this query c._ts > "2017-08-18" but it does not return any document. I also tried c._ts > 2017-08-18 without the quotes but that returns all documents, even those before that date, just as if there was no query at all. Looking at the documents, I do not even see a '_ts' field. Is there any way I can delete those documents?
Thanks.
_ts is Azure Cosmos DB's internal Timestamp property
The _ts field is a unix-style epoch timestamp representing the date and time. The _ts field is updated every time a document is modified.
If you want to query in a date range, we can do that easliy with udf function, more details please refer to another SO thread.
SELECT * FROM c where udf.udfname(c._ts)>'2017-08-18'
udf function
function epochToDate (ts) {
return new Date(ts*1000);
}
According to
https://msdn.microsoft.com/en-us/library/azure/microsoft.azure.documents.resource.timestamp.aspx#P:Microsoft.Azure.Documents.Resource.Timestamp
_ts gets the last modified timestamp associated with the resource from the Azure DocumentDB database service.
[JsonPropertyAttribute(PropertyName = "_ts")]
[JsonConverterAttribute(typeof(UnixDateTimeConverter))]
public virtual DateTime Timestamp { get; internal set; }
Its is represented as a POSIX or epoch time value. Its the number of seconds that have elapsed since 00:00:00 (UTC), 1 January 1970.
Related
I have a field in one of my mongodb collection that stores date in below format:
{
name:"ABC",
LAST_UPDATED:"10/10/2022 6:0"
},
{
name:"ABC",
LAST_UPDATED:"10/10/2022 6:15"
}
...
New data is added to this collection every 15 min.Everyday this collection will be cleaned at 12AM, so the date would be same in every document. Now I want to query for documents which have LAST_UPDATED time between 6:30 and 8:45. I have written below query:
db.collection_name.find({$and:[{LAST_UPDATED:{$gte:"10/10/2022 6:30"}},{LAST_UPDATED:{$lte:"10/10/2022 8:15"}}]});
The issue is that above query works only for some time ranges. It doesn't work for every input. I cannot also use mongodb date format.
Is there any way to find documents in a given time range considering that the format of LAST_UPDATED field will not be changed?
Thank You!
Let's say I have an date attribute stored in the format dd/MM/YYYY HH:mm:ss i.e. 22/12/2021 10:15:23. Now I just want 22/12/2021 as a date value so that I can do date comparisons. I want this operation to happen at database itself so that I can do date comparisons as part of the query/aggregation itself. Please note I am using Spring MongoDB driver.
Getting date alone from a datetime string is not possible in MongoDB since it always returns an ISO date with time. As a workaround we can convert the time HH:mm:ss to 00:00:00 either by applying String operations on the string attribute or by using Arithmetic operations on the date. We will have to add a temporary field in the query which will hold the converted value using add field operations. And then we can compare them with a given date.
Please advise how to query firestore collection on timestamp field?
Query below returns nothing even if there are multiple documents with filled date field (timestamp type) exist in db:
db.collection("users").doc('john').
collection("comment").
where("date", ">", 0).
get()
For you to be able to query using date fields, you need to compare a date - in this case, the date field from your document - to a date as well. The 0 is not considered a number 0, so this affects the comparison.
It needs to be something like this: where("date", ">", new Date()). In case you want to compare dates based in epoch timestamp, a good solution is convert the new date using the where like this: where("date", ">", new Date(epoch*1000)) as mentioned. Once you using comparison in the where part of the query, the returns should occur correctly.
Besides that, more examples of converting timestamps for Firestore can be found here.
I am using JPA Query Language to retrieve data from the database. This is my class mapped to the database.
class Test {
Long id;
Date date;
}
I need to count the number of records for each date (such as 2014-09-12) through group by. I cannot seem to find a function that allow me to change a date (having values in hour, minute, etc.) into a string in the format of 2014-09-12 or removing a date's hour, minute, second, etc.
Thanks!
Well. That's it.
I have a documet with Datetime field in it. Now I need to perform atomic operation that will increase this value on some period, f.e. one day.
How to do that?
And ultimately I need to do that via morphia, if you know how to, please share.
Dates are milliseconds since the Unix epoch (MongoDB Dates).
So you can query for the document with the date you want to increment and add (inc/dec in Morphia) the number of ms you need - for example for a day.