0

I'm handling data imported to a MongoDb Collection from a Stripe-generated CSV of customers. Some fields from this CSV have spaces in the name, like Card ID, Card Brand and many others.

I'm having a problem accessing these name in the resulting objects of a .find() query:

StripeCustomer.find().then(
(customers) => {
  console.log("customer[1]:", customers[1]);
  console.log("id:", customers[1]['id']);
  console.log("Card ID:", customers[1]['Card ID']);
  res.json({
    code: 200,
    message: 'success',
    total: customers.length,
    data: customers
  })
}

The Card ID property returns undefined.

I tried using encodeURIComponent or other string conversion functions for the property name customers[0][encodeURIComponent('Card ID')] but without result.

1 Answer 1

1

I finally solved it using the .get() function:

console.log("Card ID:", customers[1].get('Card ID'));

I hope this can save somebody else's time.

Cheers!

Not the answer you're looking for? Browse other questions tagged or ask your own question.