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": {} | |
} | |
] | |
} |
This would be ideal when it comes to manipulating an order and adding a order.transaction
next to the order.transactions
. One being the new Date()
object that I can sort by, and the other being a array
.
var key;
var(key in order.transactions){
var value = orders[key];
if(value.kind === "sale" || value.kind === "capture" && value.status === "success"){
order.transaction = {
"created_at":value.created_at,
}
}
}
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?
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
so I would do
for (i in obj) { // obj being your returned json
if (obj[i].kind === 'sale') {
console.log('got it');
}
}
am i on the right track?