Mongo Import - Date Format

1,333 views
Skip to first unread message

Mark Spoto

unread,
Nov 20, 2013, 4:40:44 PM11/20/13
to mongod...@googlegroups.com
I am trying to load data using the mongo import.  My questions is focused on how to import a date.  I know how to insert a record with the correct date format, but each time I try to import date using ISODate("<date>") or new ISODate("<date>") or Date("<date>") it keeps it in that format and treats the field as a string.  I want the field to be an ISODate object so the C# driver handles it properly.  What am I doing wrong or what is the correct way to import a datetime field?

Jeff Lee

unread,
Nov 20, 2013, 6:38:31 PM11/20/13
to mongod...@googlegroups.com
Hey Mark,

You can create a new Date using the ms since epoch.

e.g.

15:32:13 [jl...@Jeffs-MacBook-Air.local] - /Users/jlee/dbvol/data
$ echo "{_id:1, ts:new Date("`date +%s`000")}" | mongoimport -h localhost -d test -c foodle
connected to: localhost
Wed Nov 20 15:32:19.103 imported 1 objects

15:32:19 [jl...@Jeffs-MacBook-Air.local] - /Users/jlee/dbvol/data
$ mongo --eval "printjson(db.foodle.findOne())"
MongoDB shell version: 2.4.8
connecting to: test
{ "_id" : 1, "ts" : ISODate("2013-11-20T23:32:18Z") }



On Wed, Nov 20, 2013 at 1:40 PM, Mark Spoto <mss...@gmail.com> wrote:
I am trying to load data using the mongo import.  My questions is focused on how to import a date.  I know how to insert a record with the correct date format, but each time I try to import date using ISODate("<date>") or new ISODate("<date>") or Date("<date>") it keeps it in that format and treats the field as a string.  I want the field to be an ISODate object so the C# driver handles it properly.  What am I doing wrong or what is the correct way to import a datetime field?

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages