In SpringBoot Applicaton,when i query mongo like this in MongoRepository:
@Aggregation({
"{$match:{createUid: ?0}}",
"{$lookup: {from: 't_user',localField: 'contactUid',foreignField:'_id',as: 'contact'}}",
"{$addFields: {contact:{$arrayElemAt: ['$contact',0]} }}",
"{$project: { 'contact.password': 0,'contact.salt': 0}}",
})
List<HashMap> searchSentAddContacts(ObjectId createUid);
The $Project action just set contact.password and contact.salt to null in final result list,didn't exclude the fields. But when i use the same query in mongo console,it works well.'contact.password' and 'contact.salt' are gone in result.
Here is my collection strcut: 't_add_contacts':
[
{
"_id": {"$oid": "66ef75795e8146631d0658bc"},
"_class": "org.tzx.xim.entity.AddContactsEntity",
"addType": 0,
"contactUid": {"$oid": "66ef75505e8146631d0658bb"},
"createTime": {"$date": "2024-09-22T01:40:09.665Z"},
"createUid": {"$oid": "66ef75425e8146631d0658ba"},
"updateTime": {"$date": "2024-09-22T01:40:09.665Z"}
}
]
't_user':
[
{
"_id": {"$oid": "66ef75425e8146631d0658ba"},
"_class": "org.tzx.xim.entity.UserEntity",
"createTime": {"$date": "2024-09-22T01:39:14.569Z"},
"loginName": "user1",
"nickName": "haha1",
"password": "123456",
"salt": "awsddqwdqwd",
"updateTime": {"$date": "2024-09-22T01:39:14.569Z"}
}
]
Thanks everyone!
Query collection 't_add_contacts' and join part of collection 't_user'.