I'm having issue with adding a key value pair to an array that has the same name. Is there a way to add it according to index?
I've tried finding key in the search query which works. But updating adds it the bottom of the document
db.getCollection('siteLog').updateOne(
{
'site':'test1',
'items.suspiciousActivity.source': 'Account Added to Admin Group'
},
{$set:
{'items.suspiciousActivity.source.Account Added to Admin Group' : 'summary':'test1'}
})
It should be added towards the bottom with another key value pair
"items" : [
{
"suspiciousActivity" : {
"source" : "Account Added to Admin Group",
"count" : "2",
"summary" : "Test summary for this"
}
},
{
"suspiciousActivity" : {
"source" : "Palo Alto FW - Local Account Login",
"count" : "2",
"summary" : "Another test summary"
}
},
{
"suspiciousActivity" : {
"source" : "Suspicious Failed Logon Attempts",
"count" : "2",
"summary": "more summaries"
}
},