0
db.students.insertOne({
  _id: 1001,
  Firstname: "John",
  Lastname: "smith",
  Address: {
    Streetaddress: "123 Monash Drive",
    Suburb: "Clayton",
    State: "VIC",
    Postcode: 3168,
  },
  Gender: "Male",
  Course: "BITS",
  Year: 2019,
  "Off-Campus": "false",
  Email: ["jsmith@gmail.com", "jsmith@yahoo.com"],
});

After type these, i got the error of uncaught exception: SyntaxError: missing : after property id :. Idk why this happen.

Shubham Verma
  • 4,918
  • 1
  • 9
  • 22
  • 1
    Check the older thread [https://stackoverflow.com/questions/38930207/query-in-mongo-shell-gives-syntaxerror-missing-after-property](https://stackoverflow.com/questions/38930207/query-in-mongo-shell-gives-syntaxerror-missing-after-property) – kmShelke Aug 23 '20 at 11:57

1 Answers1

0

The document which you are trying to insert isn't a valid JSON, try with the following -

db.students.insertOne({
    "_id": 1001,
    "Firstname": "John",
    "Lastname": "smith",
    "Address": {
        "Streetaddress": "123 Monash Drive",
        "Suburb": "Clayton",
        "State": "VIC",
        "Postcode": 3168
    },
    "Gender": "Male",
    "Course": "BITS",
    "Year": 2019,
    "Off-Campus": "false",
    "Email": [
        "jsmith@gmail.com",
        "jsmith@yahoo.com"
    ]
});
Kunal Mukherjee
  • 5,775
  • 3
  • 25
  • 53