技术笔记Notes

Posted by 夏飞 on 2019-11-04

dubbo RPCcontext 分析

MongoDB实现case when 和 id in的查询

1
2
3
4
5
6
7
8
9
10
db.store.aggregate([{
$project: {
"nczStoreId": 1,
"storeName": 1,
"groupIds": 1,
"priority": {
$cond: { if: { $setIsSubset: [ "$groupIds",[1000] ]}, then: 1, else: 0 }
}
}
}])

放回 当groupIds集合中包含1000 返回auth=true

$cond 判断表达式文档
https://docs.mongodb.com/v3.2/meta/aggregation-quick-reference/#expressions

它有下面几种表达式判断

Boolean Expressions

$and $or 用于表达式嵌套
result: { $and: [ { $gt: [ “$qty”, 100 ] }, { $lt: [ “$qty”, 250 ] } ] }

Set Expressions

判断集合是否包含 $setIsSubset

ComparisonExpressions

$eq $gt

Arithmetic Expressions

用来做计算$abs $floor

String Expressions

字符串运算
$concat $substr

Text Search expressions

$meta

Array Expressions

$size

Date Expressions

等等

JavaAPI实现

1
2
3
4
5
6
7
8
9
10
11
12
13
BasicDBObject bson = new BasicDBObject();
bson.put("$eval","db.store.aggregate([{\n" +
" $project: {\n" +
" \"nczStoreId\": 1,\n" +
" \"storeName\": 1,\n" +
" \"groupIds\": 1,\n" +
" \"auth\": {\n" +
" $cond: { if: { $setIsSubset: [ \"$groupIds\",[1000] ]}, then: true, else: false }\n" +
" }\n" +
" }\n" +
"}])");
Object o=mongoTemplate.getDb().runCommand(bson);
System.out.println(o.toString());

Servlet笔记

HttpServletRequest

GET http://localhost:8080/test?a=1

request.getRequestURL();

http://localhost:8080/test

request.getRequestURI();

/test

request.getQueryString();

a=1