[英]Manipulating the String
I want to manipulate the String. 我想操纵字符串。 Example: 例:
RegistrationRequest.find({ 'serviceRequest.serviceRequestSubtype.masterCode': 'RETPOSTREG', $and: [ { 'serviceRequest.serviceRequestStatus.masterCode': 'COMPLETED' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.serviceStatus.masterCode': 'ACT' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.technology.masterCode': 'GSM' } ] } ] } ] }, {'serviceRequest.customer.profileDetails.basicDetails.customerCode': 1,_id:0}).sort({"serviceRequest.modifiedDate": 1})
I want to separate the above into 3 strings 我想将以上内容分成3个字符串
which are like below: 如下所示:
query = { 'serviceRequest.serviceRequestSubtype.masterCode': 'RETPOSTREG', $and: [ { 'serviceRequest.serviceRequestStatus.masterCode': 'COMPLETED' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.serviceStatus.masterCode': 'ACT' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.technology.masterCode': 'GSM' } ] } ] } ] }
projection = {'serviceRequest.customer.profileDetails.basicDetails.customerCode': 1,_id:0}
sort = {"serviceRequest.modifiedDate": 1}
i am able to separate sort as below - sort may not be there always. 我能够按如下所示进行排序-排序可能并不总是存在。
if(query.contains("sort"))
{
String sortParams = query.substring(query.lastIndexOf(".")+1, query.lastIndexOf(")")-1);
}
got other value as 得到其他价值
String parseQuery = query.substring(query.indexOf("(")+1, query.lastIndexOf(".")-2);
now the parseQuery has string: 现在parseQuery具有字符串:
{ 'serviceRequest.serviceRequestSubtype.masterCode': 'RETPOSTREG', $and: [ { 'serviceRequest.serviceRequestStatus.masterCode': 'COMPLETED' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.serviceStatus.masterCode': 'ACT' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.technology.masterCode': 'GSM' } ] } ] } ] }, {'serviceRequest.customer.profileDetails.basicDetails.customerCode': 1,_id:0}
Now i need to separate the above as two strings, the string between last {} are projections in mongodb that i want as separate string say projection. 现在,我需要将以上内容分隔为两个字符串,last {}之间的字符串是mongodb中的投影,我希望将其作为单独的字符串(即投影)。
can any one help me on this. 谁可以帮我这个事。
Thanks Sarada 谢谢萨拉达
I am able to manipulate the string. 我能够操纵字符串。 Below is the code : 下面是代码:
String sortParams="";
String findParams = "";
String returnParams="";
//if sort is there then this keyword will be there
String sortStr = "sort";
//if return params exist then only the below substring will be there
String retStr="]},{";
//remove extra spaces in the query
query = query.replaceAll(" ", "");
if(query.contains(sortStr))
{
sortParams = query.substring(query.lastIndexOf(sortStr)+5, query.lastIndexOf(")"));
query = query.substring(0, query.lastIndexOf(sortStr)-1);
}
if(query.contains(retStr))
{
returnParams = query.substring(query.lastIndexOf(retStr)+3, query.length()-1);
query = query.substring(0, query.lastIndexOf(retStr)+2)+")";
}
findParams = query.substring(query.indexOf("(")+1, query.length()-1);
eg:- Actually Query : 例如:-实际上查询:
RegistrationRequest.find({ 'serviceRequest.serviceRequestSubtype.masterCode': 'RETPOSTREG', $and: [ { 'serviceRequest.serviceRequestStatus.masterCode': 'COMPLETED' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.serviceStatus.masterCode': 'ACT' }, { $and: [ { 'serviceRequest.customer.services.service.0.serviceDetails.technology.masterCode': 'GSM' } ] } ] } ] }, {'serviceRequest.customer.profileDetails.basicDetails.customerCode': 1,_id:0}).sort({serviceRequest.modifiedDate})
after exeuction of if(query.contains(sortStr)) statement 执行if(query.contains(sortStr))语句后
sortparams : {'serviceRequest.modifiedDate':1}
Query after sort params removed :RegistrationRequest.find({'serviceRequest.serviceRequestSubtype.masterCode':'RETPOSTREG',$and:[{'serviceRequest.serviceRequestStatus.masterCode':'COMPLETED'},{$and:[{'serviceRequest.customer.services.service.0.serviceDetails.serviceStatus.masterCode':'ACT'},{$and:[{'serviceRequest.customer.services.service.0.serviceDetails.technology.masterCode':'GSM'}]}]}]},{'serviceRequest.customer.profileDetails.basicDetails.customerCode':1,_id:0})
after exeuction of if(query.contains(retStr)) executed 执行完if(query.contains(retStr))后
returnParams :{'serviceRequest.customer.profileDetails.basicDetails.customerCode':1,_id:0}
Query after return params removed :RegistrationRequest.find({'serviceRequest.serviceRequestSubtype.masterCode':'RETPOSTREG',$and:[{'serviceRequest.serviceRequestStatus.masterCode':'COMPLETED'},{$and:[{'serviceRequest.customer.services.service.0.serviceDetails.serviceStatus.masterCode':'ACT'},{$and:[{'serviceRequest.customer.services.service.0.serviceDetails.technology.masterCode':'GSM'}]}]}]})
after execution of last statement 执行最后一条语句后
findParams :{'serviceRequest.serviceRequestSubtype.masterCode':'RETPOSTREG',$and:[{'serviceRequest.serviceRequestStatus.masterCode':'COMPLETED'},{$and:[{'serviceRequest.customer.services.service.0.serviceDetails.serviceStatus.masterCode':'ACT'},{$and:[{'serviceRequest.customer.services.service.0.serviceDetails.technology.masterCode':'GSM'}]}]}]}
Thanks Sarada 谢谢萨拉达
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.