I have two collections community and profile.
community collection sample data:
_id : ObjectId("5dc1f30abcafe70001bd0075")
communityname : "testing1",
user_id : ObjectId("5dc1f2ed4a59120001a4d09d")
active_flag : 0
_id : ObjectId("5dc1f30abcafe70001bd0082")
communityname : "testing1",
user_id : ObjectId("5dc4a8b7360a0100012d3ec8")
active_flag : 0
profile collection sample data:
_id : ObjectId("5dc1f2ed4a59120001a4d09d"),
username : "Haneesh",
"name" : "hani"
_id : ObjectId("5dc4a8b7360a0100012d3ec8"),
username : "Harish",
name : "Hari"
I write the lambda function like this below.
community =db.community
comm_id = ObjectId(event['c_id'])
user1 = list(community.aggregate([{
"$match" : { "_id" : comm_id }
},
{
"$lookup" : {
"from" : "profile",
"localField" : "user_id",
"foreignField" : "_id",
"as" : "details"
}
},
{ "$unwind" : "$details" },
{
"$project" : {
"_id" : 0,
"username" : "$details.username",
"name" : "$details.name"
}
}
]))
user2 = json.loads(json.dumps(user1, default=json_util.default))
return user2
I have executed the lambda function, I'm getting output like this below:
[
{
"username": "anvithpm026",
"name": "Anvith P M"
},
{
"username": "shailu",
"name": "shail"
},
{
"username": "sukumar",
"name": "suku"
}
]
Now my concern is, how to search matched list. Example if a letter matchs with the username, then it get the username along with name. I've tried to use the regular expression but it didn't work. Please help me with a solution. Thanks in advance.