TypeError, admin.firestore(…).collection(…).doc(…).collection(…).doc(…).get.then is not a function












-2















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)









share|improve this question

























  • 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
















-2















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)









share|improve this question

























  • 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














-2












-2








-2


0






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)









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 using document instead of doc.

    – 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











  • *****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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer
























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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.






share|improve this answer
























  • 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
















0














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.






share|improve this answer
























  • 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














0












0








0







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter