本文介绍了如何比较mongoDB spring数据中的两个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较mongoDB spring数据中的两个字符串.
我的代码:

i'm trying to compare two string in mongoDB spring Data.
My Code:

@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;

    }

在上面的代码" creationTime "中, mongoDB中的" lastModified "列.我正在比较这两个字段,但计数不正确.这样对吗?如果不对,我该如何比较两个文件?

In the above code "creationTime" & "lastModified" columns in mongoDB.I'm comparing those two fields, but its not giving correct count. Is this correct? if it is wrong, How can i compare two fileds?

推荐答案

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

Standard query operations do not compare the values of one field against another. In order to do this, you need to employ the JavaScript evaluation server side which can actually compare the two field values:

假设两个字段都是ISODate实例

Assuming both fields are ISODate instances

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

这篇关于如何比较mongoDB spring数据中的两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 00:10