From mongoshell how to insert utc datetime and epoch values as utc datetimes into mongodb - mongo-shell

Trying to do a proof of concept of loading sample tick data into mongo db and the tick archive data is generally in utc and epoch and need to load it as is and output as utc only not local datetimes.
How to insert utc datetime and epoch in mongodb without being cast into utc again and retrieve the
same as utc only.
db.equity_ticks.insert(
{
"SNAPSHOT_DTTM" : Date("2013-07-09 19:00:00.000000"),
"CLOSE_DATE" : Date(15895) ,
"PREV_DAY_CLOSE_DATE" : Date(15895)
}
instead it inserted the local CST and output as CST too !
db.equity_ticks.find().pretty()
{
"_id" : ObjectId("52040942e5171b792b258ae8"),
"SNAPSHOT_DTTM" : "Thu Aug 08 2013 16:10:26 GMT-0500 (CDT)",
"CLOSE_DATE" : "Thu Aug 08 2013 16:10:26 GMT-0500 (CDT)",
"PREV_DAY_CLOSE_DATE" : "Thu Aug 08 2013 16:10:26 GMT-0500 (CDT)"
}
any help is appreciated.

Related

postgresql convert 'Thu Jul 02 13:36:17 UTC 2020' to timestamp

I have a string that I need to insert into a table as a timestamp.
'Thu Jul 02 13:36:17 UTC 2020'
Without UTC the following conversion works
SELECT to_timestamp('Thu Jul 02 13:36:17 2020', 'Dy Mon dd HH24:MI:SS yyyy');
How can I convert the timestamp with the UTC portion?
Any help would be greatly appreciated!
Database Type: PostgreSQL
Table Data Type: timestamp (this can change if needed)
If it's always going to be UTC, then you can use:
> select to_timestamp(
'Thu Jul 02 13:36:17 UTC 2020',
'Dy Mon DD HH24:MI:SS UTC YYYY'
);

find results not matching date in selector

A Meteor client Template returns mongodb cursor. The collection has 3 documents which contain date field. I expected the find to return 3 documents, but it only gave one the date of which is Mon Aug 08 2016 00:00:00 GMT+1000 (AEST).
Why is that and how can I get the 3 documents? Thanks
"date" : ISODate("2016-08-08T14:00:00Z"),
"date" : ISODate("2016-08-08T14:00:00Z"),
"date" : ISODate("2016-08-07T14:00:00Z"),
console.log(start); //=> Sun Aug 07 2016 00:00:00 GMT+1000 (AEST)
console.log(end); //=> Mon Aug 08 2016 00:00:00 GMT+1000 (AEST)
console.log(myCol.find({date: {$gte: start, $lte: end}}).fetch()); // expected 3 not just 1
the code below shows how the date was before inserting in the collection.
const date = cheerioObj(this).next().html().trim();
const dArr = date.split('/');
const dObj = new Date(parseInt(dArr[2]), parseInt(dArr[1]) - 1, parseInt(dArr[0]));
EDIT: Sorry, it's late.
It may be to do with your .fetch() method. Try iterating the cursor instead:
var myArray = db.users.find({...}).toArray();
Then access each in a for loop.

Extjs Grid updating Issue in Date Field

I have 3 datefield in grid and when I am updating anything in row, it shows red mark on date field that means date fields are also modified but I am not making any change in any date field.
I tried to find out problem and I got following reason:
context.originalValues.dateCreated : 11/10/2014
context.originalValues.dateModified : 11/10/2014
context.originalValues.lastLogin : 11/10/2014
and
context.newValues.dateCreated : Mon Nov 10 2014 00:00:00 GMT+0530 (IST)
context.newValues.dateModified : Mon Nov 10 2014 00:00:00 GMT+0530 (IST)
context.newValues.lastLogin : Mon Nov 10 2014 00:00:00 GMT+0530 (IST)
so, grid shows these dates columns are updated. Is there any way to solve this issue.
Thanks in Advance.
Solved the issue :)
The date in store was in string format so created date object in Store, and now it is working fine. I used following codes to create date object in store.
{
name: 'lastLogin',
type: 'date',
dateFormat: 'n/j/Y',
convert: function (newValue, model)
{
return new Date(model.get('lastLogin'));
}
}

Go language time.Parse() for timestamps with no timezone

In Go I'm trying to use the time.Parse() function from the time package to convert a string timestamp into a Time object. I know Go has an uncommon way of representing the time format your timestamps are in by providing it with an example of how their reference time (Mon Jan 2 15:04:05 -0700 MST 2006) would be displayed in your format. I'm still having issues with errors however. Here is an example of one of my timestamps:
Tue Nov 27 09:09:29 UTC 2012
Here is what the call I'm making looks like:
t, err := time.Parse("Mon Jan 02 22:04:05 UTC 2006", "Tue Nov 27 09:09:29 UTC 2012")
So basically what I've done here is try and match the formatting for day name/month name/day number, the hour/minute/second format, the string literal "UTC" and the year format. Note that I've increased the hours field of the Go reference format by 7 (from 15 to 22) to account for the fact that their timestamp is in a negative 7 timezone and all my timestamps are in a UTC timezone.
The error I get is:
parsing time "Tue Nov 27 09:09:29 UTC 2012" as "Mon Jan 02 22:04:05 UTC 2006": cannot parse ":09:29 UTC 2012" as "2"
What am I doing wrong here? Am I misinterpreting how to use time.Parse() or is my use case not supported for some reason?
Your format string should be:
Mon Jan 02 15:04:05 MST 2006
playground
That is, use MST for the timezone and 15 for the hour, as documented in your linked Parse function.
In this case, you can use time.UnixDate:
package main
import (
"fmt"
"time"
)
func main() {
t, e := time.Parse(time.UnixDate, "Tue Nov 27 09:09:29 UTC 2012")
if e != nil {
panic(e)
}
fmt.Println(t)
}
https://golang.org/pkg/time#UnixDate

Date object in a MongoDB collection

In a collection in my MondoDB database i have a collection like follows:
{ "_id" : ObjectId("4d0d3945e69a56cf504375b7"), "action" : "Click", "dt" : "Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)"}
dt is a Date object. If i do db.mycollection.find({action:"Click"})the record comes up. But db.mycollection.find({dt:'Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)'})does not show any records, since i guess dt is a Date object.
How to query by dt in the above case ?
Please Help
Thank You
db.mycollection.find({dt:ISODate('Sun Dec 19 2010 03:44:21 GMT+0000 (UTC)')})