How can I fix the following error retrieving a document using firebase admin?
How can I fix the following error retrieving a document using firebase admin?
I am unable to get a single document from my firestore database. I can pull the data just fine on client side using angularfire2. But when I use the following code in cloud functions I get a random object. This the the following database schema
/networks/hzlNpVEB9nOKRdPG/companyProfiles/M6nKSjsnA9yyhvnvfB8oD/userProfiles/820RGKrdhhjoF9Ba6Zf
This is the code
const admin = require('firebase-admin');
const db = admin.firestore();
let profilesRef = db.collection("/networks/${networkProfileId}/companyProfiles/${companyProfileId}/userProfiles").doc(user.uid).get()
.then(doc =>{
if(doc.exists){
res.status(200).send({data:doc.data()});
}
})
this is the current returned object
{}
<prototype>: {…}
__defineGetter__: function __defineGetter__()
__defineSetter__: function __defineSetter__()
__lookupGetter__: function __lookupGetter__()
__lookupSetter__: function __lookupSetter__()
__proto__: Getter & Setter
constructor: function Object()
hasOwnProperty: function hasOwnProperty()
isPrototypeOf: function isPrototypeOf()
propertyIsEnumerable: function propertyIsEnumerable()
toLocaleString: function toLocaleString()
toSource: function toSource()
toString: function toString()
valueOf: function valueOf()
"
collection(`/networks/${networkProfileId}/companyProfiles/${companyProfileId}/userProfiles`)
fixed that its now
networks/${networkProfileId}/companyProfiles/${companyProfileId}/userProfiles
).doc(${user.uid}
but i still get the same error. but if I hard code the values in the string it works just fine. I also checked if the variables have values and they do– Juan Leyva
2 days ago
networks/${networkProfileId}/companyProfiles/${companyProfileId}/userProfiles
${user.uid}
What does your call to
admin.initializeApp()
look like?– Hiranya Jayathilaka
21 hours ago
admin.initializeApp()
admin.initializeApp(); Thats all I have. According to the new update you know longer need the extra parameters. If I do
('networks/453j5hn4j3k/companyProfiles/dsadiodisa988/userProfiles').doc('fdsfds7f678ds')
that works perfectly. Seems when I add variables it doesn't work. the following wont work collection(`/networks/${networkProfileId}/companyProfiles/${companyProfileId}/userProfiles`).doc(user.uid)
– Juan Leyva
13 hours ago
('networks/453j5hn4j3k/companyProfiles/dsadiodisa988/userProfiles').doc('fdsfds7f678ds')
collection(`/networks/${networkProfileId}/companyProfiles/${companyProfileId}/userProfiles`).doc(user.uid)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You're using double quotes (
"
) in your path, but seem to be also using template literals. You probably want to put that in backticks:collection(`/networks/${networkProfileId}/companyProfiles/${companyProfileId}/userProfiles`)
.– Frank van Puffelen
Jun 30 at 1:07