I have documents of the below structure:
{
"_id":{
"$oid":"6145b4405df7711fe1e2f3e0"
},
"name":"Testing1",
"description":"Testing Project1",
"created_at":{
"$date":"2021-09-18T09:41:20.985Z"
},
"updated_at":{
"$date":"2021-09-18T09:41:20.985Z"
},
"experiments":null,
"contributors":[
"local"
],
"tags":[
"dev",
"prod"
],
"owner":"localhost",
"tokens":[
{
"owner":"localhost",
"created_at":{
"$date":"2021-09-18T16:38:02.911Z"
},
"token":"testToken"
}
]
}
############
{
"_id":{
"$oid":"6145b4405df7711fe1e2f3e0"
},
"name":"Testing2",
"description":"Testing Project2",
"created_at":{
"$date":"2021-09-18T09:41:20.985Z"
},
"updated_at":{
"$date":"2021-09-18T09:41:20.985Z"
},
"experiments":null,
"contributors":[
"local"
],
"tags":[
"dev",
"prod"
],
"owner":"localhost",
"tokens":[
{
"owner":"root",
"created_at":{
"$date":"2021-09-18T16:38:02.911Z"
},
"token":"rootToken"
},
{
"owner":"localhost",
"created_at":{
"$date":"2021-09-18T16:38:02.911Z"
},
"token":"localToken"
}
]
}
- How to return only token and created_at (not the complete doc) using findOne query with _id and tokens.owner.
- If updated_at of the document is greater than tokens.owner created_at then return false.
- If I want to renew the token of the any tokens.owner, then it should update not append to tokens object.
I am learning api building in go lang with mongodb, Please help me.
Thanks.