TypeError, admin.firestore(…).collection(…).doc(…).collection(…).doc(…).get.then is not a function
I'm trying to code a function that triggers when a user gets a new comment and sends a notification.Comments are stored in /Users/{user_id}/Notifications/{notification_id}. Users save their device notification tokens to /users/{userID}
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotif = functions.firestore.document('Users/{user_id}/Notifications/{notification_id}')
.onWrite((change,context) =>
{
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
return admin.firestore().collection('Users').document(user_id).collection('Notifications').document(notification_id).get().then(queryResult=>{
const from_user_id = queryResult.data().From;
const from_data = admin.firestore().collection('Users').document(from_user_id).get();
const to_data = admin.firestore().collection('Users').document(user_id).get();
return Promise.all([from_data, to_data]).then(result => {
const from_name = result[0].data().From;
const to_name = result[1].data().From;
console.log("FROM: " + from_name + "TO: " + to_name);
});
});
});
And here's the package.json file. Everything is up-to-date
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^6.4.0",
"firebase-functions": "^2.1.0"
},
"private": true
}
Firebase gives the following error:
TypeError: admin.firestore(...).collection(...).document is not a function
at exports.sendNotif.functions.firestore.document.onWrite (/user_code/index.js:13:50)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
at /var/tmp/worker/worker.js:768:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
node.js firebase google-cloud-firestore firebase-admin
add a comment |
I'm trying to code a function that triggers when a user gets a new comment and sends a notification.Comments are stored in /Users/{user_id}/Notifications/{notification_id}. Users save their device notification tokens to /users/{userID}
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotif = functions.firestore.document('Users/{user_id}/Notifications/{notification_id}')
.onWrite((change,context) =>
{
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
return admin.firestore().collection('Users').document(user_id).collection('Notifications').document(notification_id).get().then(queryResult=>{
const from_user_id = queryResult.data().From;
const from_data = admin.firestore().collection('Users').document(from_user_id).get();
const to_data = admin.firestore().collection('Users').document(user_id).get();
return Promise.all([from_data, to_data]).then(result => {
const from_name = result[0].data().From;
const to_name = result[1].data().From;
console.log("FROM: " + from_name + "TO: " + to_name);
});
});
});
And here's the package.json file. Everything is up-to-date
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^6.4.0",
"firebase-functions": "^2.1.0"
},
"private": true
}
Firebase gives the following error:
TypeError: admin.firestore(...).collection(...).document is not a function
at exports.sendNotif.functions.firestore.document.onWrite (/user_code/index.js:13:50)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
at /var/tmp/worker/worker.js:768:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
node.js firebase google-cloud-firestore firebase-admin
As the error says you are usingdocument
instead ofdoc
.
– jal
Jan 1 at 16:54
*****Thanks****
– CM Hacks
Jan 1 at 18:50
add a comment |
I'm trying to code a function that triggers when a user gets a new comment and sends a notification.Comments are stored in /Users/{user_id}/Notifications/{notification_id}. Users save their device notification tokens to /users/{userID}
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotif = functions.firestore.document('Users/{user_id}/Notifications/{notification_id}')
.onWrite((change,context) =>
{
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
return admin.firestore().collection('Users').document(user_id).collection('Notifications').document(notification_id).get().then(queryResult=>{
const from_user_id = queryResult.data().From;
const from_data = admin.firestore().collection('Users').document(from_user_id).get();
const to_data = admin.firestore().collection('Users').document(user_id).get();
return Promise.all([from_data, to_data]).then(result => {
const from_name = result[0].data().From;
const to_name = result[1].data().From;
console.log("FROM: " + from_name + "TO: " + to_name);
});
});
});
And here's the package.json file. Everything is up-to-date
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^6.4.0",
"firebase-functions": "^2.1.0"
},
"private": true
}
Firebase gives the following error:
TypeError: admin.firestore(...).collection(...).document is not a function
at exports.sendNotif.functions.firestore.document.onWrite (/user_code/index.js:13:50)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
at /var/tmp/worker/worker.js:768:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
node.js firebase google-cloud-firestore firebase-admin
I'm trying to code a function that triggers when a user gets a new comment and sends a notification.Comments are stored in /Users/{user_id}/Notifications/{notification_id}. Users save their device notification tokens to /users/{userID}
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotif = functions.firestore.document('Users/{user_id}/Notifications/{notification_id}')
.onWrite((change,context) =>
{
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
return admin.firestore().collection('Users').document(user_id).collection('Notifications').document(notification_id).get().then(queryResult=>{
const from_user_id = queryResult.data().From;
const from_data = admin.firestore().collection('Users').document(from_user_id).get();
const to_data = admin.firestore().collection('Users').document(user_id).get();
return Promise.all([from_data, to_data]).then(result => {
const from_name = result[0].data().From;
const to_name = result[1].data().From;
console.log("FROM: " + from_name + "TO: " + to_name);
});
});
});
And here's the package.json file. Everything is up-to-date
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^6.4.0",
"firebase-functions": "^2.1.0"
},
"private": true
}
Firebase gives the following error:
TypeError: admin.firestore(...).collection(...).document is not a function
at exports.sendNotif.functions.firestore.document.onWrite (/user_code/index.js:13:50)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
at /var/tmp/worker/worker.js:768:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
node.js firebase google-cloud-firestore firebase-admin
node.js firebase google-cloud-firestore firebase-admin
edited Jan 1 at 18:29


Doug Stevenson
79.5k995113
79.5k995113
asked Jan 1 at 14:01


CM HacksCM Hacks
64
64
As the error says you are usingdocument
instead ofdoc
.
– jal
Jan 1 at 16:54
*****Thanks****
– CM Hacks
Jan 1 at 18:50
add a comment |
As the error says you are usingdocument
instead ofdoc
.
– jal
Jan 1 at 16:54
*****Thanks****
– CM Hacks
Jan 1 at 18:50
As the error says you are using
document
instead of doc
.– jal
Jan 1 at 16:54
As the error says you are using
document
instead of doc
.– jal
Jan 1 at 16:54
*****Thanks****
– CM Hacks
Jan 1 at 18:50
*****Thanks****
– CM Hacks
Jan 1 at 18:50
add a comment |
1 Answer
1
active
oldest
votes
admin.firestore().collection(...)
returns a CollectionReference object. As you can see from the linked API docs, there is no method called document() on that. But there is a doc() method. Use that instead.
worked! Thanks :)
– CM Hacks
Jan 1 at 18:46
Now i have a different problem, it says...TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 18:47
That sounds like a different question.
– Doug Stevenson
Jan 1 at 18:49
Code is same. In my firestore I have this structure Users/user_id/Notifications/notification_id... in this i have different fields from,from_ID,name,etc and I am getting this error.....TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 19:10
Because that has been solved after the answer given by you :)
– CM Hacks
Jan 1 at 19:31
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996086%2ftypeerror-admin-firestore-collection-doc-collection-doc-get-then%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
admin.firestore().collection(...)
returns a CollectionReference object. As you can see from the linked API docs, there is no method called document() on that. But there is a doc() method. Use that instead.
worked! Thanks :)
– CM Hacks
Jan 1 at 18:46
Now i have a different problem, it says...TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 18:47
That sounds like a different question.
– Doug Stevenson
Jan 1 at 18:49
Code is same. In my firestore I have this structure Users/user_id/Notifications/notification_id... in this i have different fields from,from_ID,name,etc and I am getting this error.....TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 19:10
Because that has been solved after the answer given by you :)
– CM Hacks
Jan 1 at 19:31
|
show 1 more comment
admin.firestore().collection(...)
returns a CollectionReference object. As you can see from the linked API docs, there is no method called document() on that. But there is a doc() method. Use that instead.
worked! Thanks :)
– CM Hacks
Jan 1 at 18:46
Now i have a different problem, it says...TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 18:47
That sounds like a different question.
– Doug Stevenson
Jan 1 at 18:49
Code is same. In my firestore I have this structure Users/user_id/Notifications/notification_id... in this i have different fields from,from_ID,name,etc and I am getting this error.....TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 19:10
Because that has been solved after the answer given by you :)
– CM Hacks
Jan 1 at 19:31
|
show 1 more comment
admin.firestore().collection(...)
returns a CollectionReference object. As you can see from the linked API docs, there is no method called document() on that. But there is a doc() method. Use that instead.
admin.firestore().collection(...)
returns a CollectionReference object. As you can see from the linked API docs, there is no method called document() on that. But there is a doc() method. Use that instead.
answered Jan 1 at 18:29


Doug StevensonDoug Stevenson
79.5k995113
79.5k995113
worked! Thanks :)
– CM Hacks
Jan 1 at 18:46
Now i have a different problem, it says...TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 18:47
That sounds like a different question.
– Doug Stevenson
Jan 1 at 18:49
Code is same. In my firestore I have this structure Users/user_id/Notifications/notification_id... in this i have different fields from,from_ID,name,etc and I am getting this error.....TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 19:10
Because that has been solved after the answer given by you :)
– CM Hacks
Jan 1 at 19:31
|
show 1 more comment
worked! Thanks :)
– CM Hacks
Jan 1 at 18:46
Now i have a different problem, it says...TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 18:47
That sounds like a different question.
– Doug Stevenson
Jan 1 at 18:49
Code is same. In my firestore I have this structure Users/user_id/Notifications/notification_id... in this i have different fields from,from_ID,name,etc and I am getting this error.....TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 19:10
Because that has been solved after the answer given by you :)
– CM Hacks
Jan 1 at 19:31
worked! Thanks :)
– CM Hacks
Jan 1 at 18:46
worked! Thanks :)
– CM Hacks
Jan 1 at 18:46
Now i have a different problem, it says...TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 18:47
Now i have a different problem, it says...TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 18:47
That sounds like a different question.
– Doug Stevenson
Jan 1 at 18:49
That sounds like a different question.
– Doug Stevenson
Jan 1 at 18:49
Code is same. In my firestore I have this structure Users/user_id/Notifications/notification_id... in this i have different fields from,from_ID,name,etc and I am getting this error.....TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 19:10
Code is same. In my firestore I have this structure Users/user_id/Notifications/notification_id... in this i have different fields from,from_ID,name,etc and I am getting this error.....TypeError: Cannot read property 'from' of undefined at Promise.all.then.result (/user_code/index.js:22:43) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
– CM Hacks
Jan 1 at 19:10
Because that has been solved after the answer given by you :)
– CM Hacks
Jan 1 at 19:31
Because that has been solved after the answer given by you :)
– CM Hacks
Jan 1 at 19:31
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996086%2ftypeerror-admin-firestore-collection-doc-collection-doc-get-then%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
As the error says you are using
document
instead ofdoc
.– jal
Jan 1 at 16:54
*****Thanks****
– CM Hacks
Jan 1 at 18:50