FiringBlanks
FiringBlanks

Reputation: 2084

Specify type when adding data to Firestore

I'm trying to add data to Firestore but I need to save it as a number. The problem is, Firestore automatically stores everything as a string by default. How do you change this?

  //Add to Firestore
  this.afs.collection(placeToSearchSubmit).add({
    title: thingName,
    type: thingType,
    value: thingValue    <-- I need this to be a number
  });

Upvotes: 1

Views: 1905

Answers (2)

FiringBlanks
FiringBlanks

Reputation: 2084

Figured it out. Adding + at the front of a variable automatically casts it to an integer, but it's not the only way.

Example

let thing2 = +thing.value;

Upvotes: 3

J Prakash
J Prakash

Reputation: 1333

Firestore doesn't store everything as a string untill you give it as a string type. For info please check these two link:- DATA TYPE

Add Data

Upvotes: 0

Related Questions