如何在 MongoDB 中保存新的 Date()?
How can I save new Date() in MongoDB?
当我使用以下格式在 MongoDB 中保存日期时间时,它显示:
Error "Unable to parse JSON"
{
"_id" : ObjectId("58cb759805aeeae37a56dd3d"),
"name" : "Plutus",
"admin" : "type 1",
"created" : new Date()
}
请帮助我使用上述格式的 MongoDB 在 Robomongo 中保存日期时间。
图片错误描述:
谢谢
您可以尝试使用 new ISODate("2017-03-17 11:59")
。我知道这有点麻烦,但这是唯一保证适用于所有版本的 Robomongo 和 MongoDB.
的日期值
进一步阅读 -
Robomongo 不支持这种格式,我建议你试试 MongoBooster..
MongoDB。当然它会支持 new Date() 的格式。
否则,你把日期值放在里面,比如 new Date("2017-03-17")
错误似乎与 JSON 语法有关。
那里可能有硬线中断,请尝试修剪线。请看:
Multiline strings in JSON
使用shell插入:
db.sites.insert({
“_id”:ObjectId(“58cb759805aeeae37a56dd3d”),
"name" : "Plutus",
"admin" : "type 1",
"created" : 新日期()
}
保存这个JSON
{"name": "whatever", "your_cool_date": "2017-03-17 11:59"}
它将在数据库中保存为 ISO 日期:
"your_cool_date" : ISODate("2017-03-17T10:59:00Z"),
当我使用以下格式在 MongoDB 中保存日期时间时,它显示:
Error "Unable to parse JSON"
{
"_id" : ObjectId("58cb759805aeeae37a56dd3d"),
"name" : "Plutus",
"admin" : "type 1",
"created" : new Date()
}
请帮助我使用上述格式的 MongoDB 在 Robomongo 中保存日期时间。
图片错误描述:
谢谢
您可以尝试使用 new ISODate("2017-03-17 11:59")
。我知道这有点麻烦,但这是唯一保证适用于所有版本的 Robomongo 和 MongoDB.
进一步阅读 -
Robomongo 不支持这种格式,我建议你试试 MongoBooster..
MongoDB。当然它会支持 new Date() 的格式。
否则,你把日期值放在里面,比如 new Date("2017-03-17")
错误似乎与 JSON 语法有关。
那里可能有硬线中断,请尝试修剪线。请看:
Multiline strings in JSON
使用shell插入:
db.sites.insert({ “_id”:ObjectId(“58cb759805aeeae37a56dd3d”), "name" : "Plutus", "admin" : "type 1", "created" : 新日期() }
保存这个JSON
{"name": "whatever", "your_cool_date": "2017-03-17 11:59"}
它将在数据库中保存为 ISO 日期:
"your_cool_date" : ISODate("2017-03-17T10:59:00Z"),