在python文件中创建Date()时出现MongoDB Throwing Syntax错误

时间:2017-04-03 07:15:41

标签: python mongodb mongodb-query

当我在mongodb shell中运行以下命令时,它运行正常

db.abcd_vehiclestate.count({"createdAt" : {"$lt": new Date("2017-03-27T00:00:00.000Z")}})

但是当我把它放在python脚本里面时抛出语法错误

""testcount = db[col].count({"CreatedAt" : {'$lt':new Date("2017-03-28") }})                                                           ^
SyntaxError: invalid syntax""

1 个答案:

答案 0 :(得分:0)

原因create table Poll_Question_Table ( PollQuestionId int primary key, PollQuestionTex varchar(max), PollStatus int , PollStartDate date, PollEndDate date, PollCatagoryId int foreign key references Poll_Catagory_Table on update cascade on delete cascade ) create table Poll_Catagory_Table( PollCatagoryId int primary key, PollCatagoryName varchar(100), PollCatagoryDescription varchar(max) ) create table Poll_Answer_Table( PollAnswerId int primary key, PollAnswerText varchar(max), PollQuestionId int foreign key references Poll_Question_Table on update cascade on delete cascade ) create table Poll_Vote_Table ( PollVoteId int primary key, PollQuestionId int foreign key references Poll_Question_Table on update cascade on delete cascade , PollAnswerId int foreign key references Poll_Answer_Table on update cascade on delete cascade, PollCount int ) 是一种javascript语法。你应该将它转换为python语法。

试一试:

db[col].count({"CreatedAt" : {'$lt':new Date("2017-03-28") }})