mongoDB insert questions.

73 views
Skip to first unread message

William Rouse

unread,
Feb 9, 2016, 6:23:06 PM2/9/16
to mongodb-user
I have a file like this only much bigger.  When I import this file I get one _id field for all the records.  How would I write this so that each "dateField", "description" has an "-id" so it is an individual 
document.

{
dateField: "2003,02,04", description:  "Yugoslavia officially changed its name to Serbia and Montenegro.",
dateField: "2003,02,05", description:  "U.S. Secretary of State Colin Powell appeared before the United Nations Security Council to present evidence that Iraq possessed proscribed weapons of mass destruction and posed an immediate danger."
}

How would I create a new Date object when I insert into a collection?  I tried the below but that did not work.

dateField:  new Date(1830,07,28), description:   'revolution in France replaces Charles X with Louis Philippe.',

Doug

unread,
Feb 10, 2016, 9:47:36 PM2/10/16
to mongodb-user
I have a file like this only much bigger.  When I import this file I get one _id field for all the records.  How would I write this so that each "dateField", "description" has an "-id" so it is an individual 
document.

{
dateField: "2003,02,04", description:  "Yugoslavia officially changed its name to Serbia and Montenegro.",
dateField: "2003,02,05", description:  "U.S. Secretary of State Colin Powell appeared before the United Nations Security Council to present evidence that Iraq possessed proscribed weapons of mass destruction and posed an immediate danger."
}

Hi William, the above is a single JSON object that has multiple `dateField` and `description` fields. You would need to massage your file so that each line was it's own object:

{"dateField": "2003,02,04", "description": "Yugoslavia officially changed it's name to Serbia and Montenegro."}
{"dateField": "2013,02,05", "description": "U.S. Secretary of State Colin Powell appeared before the United Nations Security Council to present evidence that Iraq possessed proscribed weapons of mass destruction and posed an immediate danger."}

 
How would I create a new Date object when I insert into a collection?  I tried the below but that did not work.

dateField:  new Date(1830,07,28), description:   'revolution in France replaces Charles X with Louis Philippe.',

Doing this insert works just fine for me, but remember that in Javascript, months are 0 based (January is 0, February is 1, December is 11), so the above insert will change the date to be '1830-08-28'. Are you getting errors with your insert? If so, please let us know what they are.

Hopefully this helps you out.

Cheers!

~Doug

William Rouse

unread,
Feb 12, 2016, 11:57:20 PM2/12/16
to mongodb-user
Doug:
both your comments were helpful.  I was able to use your comments to move on.  Thanks! 
Reply all
Reply to author
Forward
0 new messages