search

Home  >  Q&A  >  body text

mongodb 命令行插入date类型报错

如何在命令行插入当前时间的数据

db.favors.insert({"xsId":ObjectId("5551335b322ae4de5a53cfa4”), "feedId" : ObjectId("555023342284ba365a652a2f"), "feedUserId" : ObjectId("554f2a9a0c02c2fa51456706"), "hasRead" : true, "date" : date.now()})

报错:2015-05-13T11:48:48.210+0800 SyntaxError: Unexpected identifier

db.favors.insert({"xsId":ObjectId("5551335b322ae4de5a53cfa4”), "feedId" : ObjectId("555023342284ba365a652a2f"), "feedUserId" : ObjectId("554f2a9a0c02c2fa51456706"), "hasRead" : true, "date" : ISODate("2015-05-11T12:49:46.121Z")})

报错:2015-05-13T11:52:40.841+0800 SyntaxError: Unexpected identifier

急急急,谢谢!

伊谢尔伦伊谢尔伦2796 days ago783

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-25 09:04:49

    db.favors.insert({"xsId":ObjectId("5551335b322ae4de5a53cfa4”), "feedId" : ObjectId("555023342284ba365a652a2f"), "feedUserId" : ObjectId("554f2a9a0c02c2fa51456706"), "hasRead" : true, "date" : date.now()})
    

    The first ObjectId("5551335b322ae4de5a53cfa4”) uses Chinese quotation marks;
    I don’t know your mongodb什么版本,date.now()是不合法的,可以使用Date()wait

    Reference
    http://www.cnblogs.com/yuechaotian/archive/2013/02/02/2889824.html

    reply
    0
  • Cancelreply