作为从MySQL迁移到MongoDB的一部分,我试图将所有mySQL查询重写为MongoDB查询。除了查询之外,我能够成功地做同样的事情
MySQL查询:
SELECT(select job_status from indexjob order by job_timestamp desc limit 1) AS job_status,(select job_timestamp from indexjob where job_status='SUCCESS' order by job_timestamp desc limit 1) AS job_timestamp;
MongoDB数据结构:
/* 1 */
{
"_id" : ObjectId("590caba811ef2308585f0dbb"),
"_class" : "com.info.sample.bean.IndexJobBean",
"jobName" : "IndexJob",
"jobStatus" : "SUCCESS",
"timeStamp" : "2017.05.05.22.13.19"
}
/* 2 */
{
"_id" : ObjectId("590caf1711ef23082cc58a3b"),
"_class" : "com.info.sample.bean.IndexJobBean",
"jobName" : "IndexJob",
"jobStatus" : "FAILED",
"timeStamp" : "2017.05.05.22.27.59"
}
编辑 - 来自评论 查询应返回上一个jobStatus =" SUCCESS"的时间戳。和最后一个jobStatus(可以是SUCCESS或FAILED)。在MySQL中,我以这种方式获取这些结果,结果将是一行,其中包含jobStatus列和具有相应值的timestamp。