1,799
社区成员




sql语句Navicat控制台输出:(也是想要的结果)
db.user.aggregate([{ "$match" : {"userId": NumberLong("4071" }} ,{$lookup: {
from: 'tb_template',
localField: 'userId',
foreignField: 'userId',
as: 'template'
}}])
以下是结果:
{
"_id": ObjectId("62a8314584ea1"),
"userId": NumberLong("4071"),
"template": [
{
"_id": ObjectId("628f39c0b594df"),
"userId": NumberLong("4071"),
"visits": NumberInt("0"),
"content": "",
"status": NumberInt("0"),
"hashMap": { },
"list": [ ],
"object": { }
}
]
}
以下是java查询代码:
Aggregation agg = Aggregation.newAggregation(
Aggregation.match(Criteria.where("userId").is(4071L)),
Aggregation.lookup("tb_template","userId","userId","template")
);
java输出结果:template.id问题出现导致前端无法使用
{
"_id": ObjectId("62a8314584ea1"),
"userId": NumberLong("4071"),
"template": [
{
"_id": {
"timestamp": 1653551504,
"counter": 11906057,
"time": 1653551504000,
"date": "2022-05-26T07:51:44.000+0000",
"timeSecond": 1653551504,
"processIdentifier": 18880,
"machineIdentifier": 2697172
},
"userId": NumberLong("4071"),
"visits": NumberInt("0"),
"content": "",
"status": NumberInt("0"),
"hashMap": { },
"list": [ ],
"object": { }
}
]
}
理想结果是:template.id=628f39c0b594df 字符串二不是一个BSON格式,
请问大神都有什么解决方法,不在查询结果过for格式化或者转义情况下,使用mongodb自带方法最好
使用template实体类