I save the information in a mongodb database, one of the fields is "date" in isodate format.
ISODate ("2019-11-22T10: 57: 47.000-05: 00"), how can I get a consultation with doctrine, version 3.4 of symfony, where I can bring the data between November 20 and 22.
I tried the following two options, but they don't work
$dataPay = $docPay->createQueryBuilder('AppBundle:TransactionPaymentez')
->field('date')->gte('2019-11-20')
->field('date')->lte('2019-11-22');
$dataPay = $docPay->createQueryBuilder('AppBundle:TransactionPaymentez')
->field('date')
->range('2019-11-20', '2019-11-22');
$dataPay = $dataPay->getQuery()->execute();
Thanks.
Related
I am new to Mongo DB.
A Collection in our mongo has data as below for one of the field.
"modifiedDate" : "11/28/2022, 06:23:01 AM"
I would like to get all such json's which has current day as "modifiedDate".
Here the date value in "modifiedDate" is stored as String instead of ISO date.
How do I filter for such records in my Criteria?
I tried doing as :
query.addCriteria(Criteria.where(MODIFIED_DATE).regex("/11\\/28\\/2022.*/", "i"));
but it returns 0 records even though there are records with the current date.
Could anyone help me ?
Thank you.
I am trying to query dates in mongodb.
The dates are stored as ISODate("2015-10-08T05:48:55.778+0000").
Now how should i do query like $gte or $lte.
I have been using Play plugin for reactive mongo
To query from the mongo shell, I would need to query with=>
{"endDateTime":{"$eq": new Date("2017-10-08T05:48:55.778+0000")}
OR,
{"endDateTime":{"$eq": ISODate("2017-10-08T05:48:55.778+0000")}
So, what should I do to query it using play reactive mongo. I have been using JodaTime. I am generating the Json Object of the query, and feeding to the find() api straightaway.
*Yes there a lot suggestion in SO, about the topic, but none of them seem to help me in this case. I could give more info if needed.
Update Answer:
Seems like I had some confusion, when converting the dates.
When I tried converting the String Date to Joda DateTime , the result when I print it in console, it would be shown as timestamp,but when I sent it to reactive mongo find it would convert to some form of string date "2015-10-08T05:48:55.778+0000".
So, I had to retrieve the millisecond conversion and send it to the respective api, and mongo would process without any issues.
I am migrating from MySQL to NoSql.Using mongo java driver I am able to insert the date fields which are currently being stored as NumberLong("1212121").However when I migrated the data from MySQL to NoSQL using Mongify the date field are getting saved as e.g ISODate("2015-04-19T18:48:38.121Z").To support the later I am trying through several options through SimpleDateFormat but could not get success to save the data in that ISODate format.
Please suggest.
I'm inserting a Mongo doc with the following time-stamp:
val format = new java.text.SimpleDateFormat("yyyyMMddHHmmss")
format.format(new Date()).toLong
Here's what the section looks like from Mongo's shell:
"{Timestamp" : NumberLong("20130919161948")}"
Based on a few tests, it appears to me that I can simply compare 2 documents by Timestamp by simply checking > or < for the yyyyMMddHHmmss format.
Please let me know if this time-stamp is OK for Mongo. Will I be able to query with it?
Mongo will not understand this as a timestamp, but as a number. As you set your date with a format going from year to seconds, you will be able to query mongo using > or < to know if it is before or after.
However if you want to mongo to treat the data as a date, you will need to use the appropriate bson date format. By having mongo treat it as a date, you will have all Mongo date operations available, like extracting year, day of week, etc.. read more
If you are using casbah, and Joda, you can enable serialization and deserialization by an explicit call:
import com.mongodb.casbah.conversions.scala._
RegisterJodaTimeConversionHelpers()
Read more here.
#Kevin, I think you are right. java.util.Date is supported in BSON object.
Using NumberLong to represent timestamp allows you to do range queries, but with BSON date type, date operation in aggregation framework becomes possible, which is more powerful.
We have some tables in mongodb which we are extracting data and loading into mysql tables through kettle. How do I get the create timestamp of a record from mongodb in kettle?
I read some articles where we can get date from objectid but I was not able to extract in kettle.
can anyone give me the syntax for extracting date from objectid or is it possible to get hidden create ts from mongodb meta layer in kettle?
Thanks,
Deepthi