I have this document:
As you can see, the field map
is of type Map. I read the data from Firestore using this function:
async function getJohn() {
var ref = doc(db, "users/john");
const document = await getDoc(ref);
if(document.exists()) {
let map = document.data().map
if (map instanceof Map) {
alert("Is a Map.")
} else {
alert("It's not a Map.")
}
}
}
Even if the map
is a Map in the document, I always get:
It’s not a Map.
How to solve this?
2
Answers
On the database side they call it a
map
, but once it arrives client side it is just a plain javascript object, never a javascriptMap
. If you want to distinguish it from other objects, maybe you could do a check like this:Firestore maps is an object so I think this will fit your needs: