如何比较mongoDB spring数据中的两个字符串?

我正在尝试比较mongoDB spring Data中的两个字符串。
我的代码:

@GET @Path("/reqvolatility") @Produces(MediaType.APPLICATION_JSON) public long getReqVolatility() throws JsonParseException, JsonMappingException, IOException{ String query = "{},{_id:0,levelId:1,reqID:1,creationTime:1,lastModified:1}"; Query query1 = new BasicQuery(query); query1.addCriteria(Criteria.where("creationTime").ne("lastModified")); long reqvolatility = getMongoOperation().count(query1,RequirmentVO.class); return reqvolatility; } 

在mongoDB中的上述代码“ creationTime ”和“ lastModified ”列中。我正在比较这两个字段,但它没有给出正确的计数。 它是否正确? 如果是错的,我如何比较两个文件?

标准查询操作不会将一个字段的值与另一个字段的值进行比较。 为此,您需要使用JavaScript评估服务器端,它实际上可以比较两个字段值:

假设两个字段都是ISODate实例

  BasicQuery query = new BasicQuery( new BasicDBObject("$where", "this.creationTime.getTime() != this.lastModified.getTime()") );