在 NoSql 中插入带日期的生日

Inserting a birthdate with Date in NoSql

我正在尝试像这样在 NoSQL 中插入日期类型的生日

db.employees.insertOne({
  "Name": "Alison Davison",
  birthday:  Date("Apr 05, 1975"),
  "Address": "874 W. Oak Place",
  "City": "Gary",
  "State": "Indiana",
  Position:{Name: "Customer Support", Remote: true, Full Time: true}
});

并抛出此错误

uncaught exception: SyntaxError: missing : after property id :
@(shell):7:63

您需要在 Date 构造函数中使用支持的格式。

new Date("<YYYY-mm-dd>") returns the ISODate with the specified date.

new Date("<YYYY-mm-ddTHH:MM:ss>") specifies the datetime in the client’s local timezone and returns the ISODate with the specified datetime in UTC.

new Date("<YYYY-mm-ddTHH:MM:ssZ>") specifies the datetime in UTC and returns the ISODate with the specified datetime in UTC.

new Date(<integer>) specifies the datetime as milliseconds since the Unix epoch (Jan 1, 1970), and returns the resulting ISODate instance.

默认不支持您尝试的格式。

Refer

并请使用以下内容。您的密钥中有一个 space。用引号括起来。

 {
  "Name": "Alison Davison",
  "birthday": new Date("1975-04-05"),
  "Address": "874 W. Oak Place",
  "City": "Gary",
  "State": "Indiana",
  "Position": {
    "Name": "Customer Support",
    "Remote": true,
    "Full Time": true
  }
}