Created
August 30, 2012 16:14
-
-
Save reggi/3532063 to your computer and use it in GitHub Desktop.
Mongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"transactions": [ | |
{ | |
"amount": "10.00", | |
"authorization": null, | |
"created_at": "2012-08-24T14:02:50-04:00", | |
"gateway": "bogus", | |
"id": 999225661, | |
"kind": "capture", | |
"order_id": 450789469, | |
"status": "success", | |
"test": true, | |
"receipt": {} | |
} | |
] | |
} | |
{ | |
"transactions": [ | |
{ | |
"amount": "10.00", | |
"authorization": null, | |
"created_at": "2012-08-24T14:02:50-04:00", | |
"gateway": "bogus", | |
"id": 999225661, | |
"kind": "sale", | |
"order_id": 450789469, | |
"status": "success", | |
"test": true, | |
"receipt": {} | |
} | |
] | |
} |
You should be able to do this. You must initialize that object property before you can work on it. If the transactions are coming in as an array of objects then you will have to loop through like so
order.transaction = [];
for (i = 0; i < order.transactions.length; i++) {
var value = order.transactions[i];
if (value.kind === 'sale' || value.kind === 'capture' && value.kind === 'success') {
order.transaction[i] = {
"created_at": value.created_at
}
}
}
console.log(order);
```javascript
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This would be ideal when it comes to manipulating an order and adding a
order.transaction
next to theorder.transactions
. One being thenew Date()
object that I can sort by, and the other being aarray
.But I am interested on not inserting this into the database, I would like to not have a fixed
order.transaction
field, and much rather generate it on-the-fly. is that possible?