0

I am learning mongoDB , version 3 and I wanted to create a collection with two fileds, a date field and a descrition field. When I try to insert a document with the below syntax, from the mongo shell, I get an error and do not know how to correct it.

> db.timeTable.insert( dateField: new Date("Oct, 04, 2012"), description:  'Next total solar eclipse visible from North America')
2016-02-08T19:34:15.474-0600 E QUERY    [thread1] SyntaxError: missing ) after argument list @(shell):1:30

How should I write this insert?

2
Contributors
3
Replies
11
Views
1 Year
Discussion Span
Last Post by rouse
0

I'm not an expert in Mongo at all but have you tried it with double quotes around the text string instead of singles?
Single quotes can be an escape character in SQL and may be in mongo too, in which case the ) isn't being read as such.

0

Yes I have tried that and it does not help. The error message points to line 1 character 30, but I don't see anything suspicious there.

0

These are the various answers that I found to resolve this:

INSERT INTO A COLLECTION VIA MONGO SHELL
dateField is a string

db.timeTable.insert({dateField:  "2007,08,07"},{description : "American baseball player Barry Bonds hit his 756th career home run, breaking the record set by Hank Aaron."});

Date field is an ISO object

db.timeTable.insert({dateField: Date("2013-08-07")},{description : "American baseball player Barry Bonds hit his 756th career home run, breaking the record set by Hank Aaron."});

This will work with mongo import if this series of 3 documents were in a file

{dateField: ISODate("2003-05-13T00:00:00Z"), description: "The First  government unveiled a new version of the $20 bill the first to be colorized in an effort to thwart counterfeiters."}
{dateField: ISODate("2003-05-13T00:00:00Z"), description: "The Second government unveiled a new version of the $20 bill the first to be colorized in an effort to thwart counterfeiters."}
{dateField: ISODate("2003-05-13T00:00:00Z"), description: "The government unveiled a new version of the $20 bill the first to be colorized in an effort to thwart counterfeiters."}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.