I'm trying to insert a transaction into the transaction list.
This is the document:
{
"_id" : ObjectId("5cb26787c3eb6c8229a92954"),
"first_name" : "testing",
"last_name" : "testing",
"ssn" : "123456789",
"address" : "123 testing st",
"account" : {
"account_number" : 32362897,
"last_access_timestamp" : "2019-04-13 18:49:43",
"account_type" : [
{
"checking" : {
"balance" : 0,
"transaction" : [ ]
}
},
{
"saving" : {
"balance" : 0,
"transaction" : [ ]
}
}
]
}
}
The ssn is supposed to be unique so I'm using that as the matching criteria. This is the query I'm using to insert into the checking transaction list:
db.customer.update({'ssn': '123456789'},
{'$push': {'account.account_type.checking.transaction': {
'amount': 120,
'transaction_type': 'deposit',
'timestamp': '11:11:11'
}}})
The expected outcome is:
{
"_id" : ObjectId("5cb26787c3eb6c8229a92954"),
"first_name" : "testing",
"last_name" : "testing",
"ssn" : "123456789",
"address" : "123 testing st",
"account" : {
"account_number" : 32362897,
"last_access_timestamp" : "2019-04-13 18:49:43",
"account_type" : [
{
"checking" : {
"balance" : 0,
"transaction" : [{
"amount": 120,
"transaction_type": "deposit",
"timestamp": "11:11:11"
} ]
}
},
{
"saving" : {
"balance" : 0,
"transaction" : [ ]
}
}
]
}
}
This is the error message I'm getting:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 28,
"errmsg" : "Cannot create field 'checking' in element {account_type: [ { checking: { balance: 0, transaction: [] } }, { saving: { balance: 0, transaction: [] } } ]}"
}
})