cloud firestore search by child value












0















I am searching a record in child level using one of the key called email ID, but it always returning null. Below is my collection data base and Query.



enter image description here



exports.authVerfication = functions.https.onRequest((req,res)=>{
if(req.method!=='POST'){
return res.status(500).json({
message:'Not allowed'
});
}

const p3= db.collection('Users').where('state', '==', 'Kar').get();
const p2= p3.then(snapshot =>{
if (!snapshot.exists) {
res.status(204).send({message:'No users found'});
} else {
res.status(200).send(snapshot.data());
}
})









share|improve this question

























  • What do you mean by "returning null". How do you display the results? In other words, what is after the .get()??

    – Renaud Tarnec
    Nov 22 '18 at 13:49













  • const p3= db.collection('Users').where('state', '==', 'Kar').get(); const p2= p3.then(snapshot =>{ if (!snapshot.exists) { res.status(204).send({message:'No users found'}); } else { res.status(200).send(snapshot.data()); } }) This is how i m returning an API results.

    – Praveen Linge gowda
    Nov 22 '18 at 13:50













  • Can you modify your original question with this part of the code? Thx

    – Renaud Tarnec
    Nov 22 '18 at 13:51











  • Yep, it works by adding doc.data() as you suggested. Thanks!

    – Praveen Linge gowda
    Nov 22 '18 at 14:10











  • Glad I could help. You may accept my answer by clicking on the grey checkmark next to the answer and turn it to green, see stackoverflow.com/help/someone-answers. Thanks.

    – Renaud Tarnec
    Nov 22 '18 at 14:38
















0















I am searching a record in child level using one of the key called email ID, but it always returning null. Below is my collection data base and Query.



enter image description here



exports.authVerfication = functions.https.onRequest((req,res)=>{
if(req.method!=='POST'){
return res.status(500).json({
message:'Not allowed'
});
}

const p3= db.collection('Users').where('state', '==', 'Kar').get();
const p2= p3.then(snapshot =>{
if (!snapshot.exists) {
res.status(204).send({message:'No users found'});
} else {
res.status(200).send(snapshot.data());
}
})









share|improve this question

























  • What do you mean by "returning null". How do you display the results? In other words, what is after the .get()??

    – Renaud Tarnec
    Nov 22 '18 at 13:49













  • const p3= db.collection('Users').where('state', '==', 'Kar').get(); const p2= p3.then(snapshot =>{ if (!snapshot.exists) { res.status(204).send({message:'No users found'}); } else { res.status(200).send(snapshot.data()); } }) This is how i m returning an API results.

    – Praveen Linge gowda
    Nov 22 '18 at 13:50













  • Can you modify your original question with this part of the code? Thx

    – Renaud Tarnec
    Nov 22 '18 at 13:51











  • Yep, it works by adding doc.data() as you suggested. Thanks!

    – Praveen Linge gowda
    Nov 22 '18 at 14:10











  • Glad I could help. You may accept my answer by clicking on the grey checkmark next to the answer and turn it to green, see stackoverflow.com/help/someone-answers. Thanks.

    – Renaud Tarnec
    Nov 22 '18 at 14:38














0












0








0








I am searching a record in child level using one of the key called email ID, but it always returning null. Below is my collection data base and Query.



enter image description here



exports.authVerfication = functions.https.onRequest((req,res)=>{
if(req.method!=='POST'){
return res.status(500).json({
message:'Not allowed'
});
}

const p3= db.collection('Users').where('state', '==', 'Kar').get();
const p2= p3.then(snapshot =>{
if (!snapshot.exists) {
res.status(204).send({message:'No users found'});
} else {
res.status(200).send(snapshot.data());
}
})









share|improve this question
















I am searching a record in child level using one of the key called email ID, but it always returning null. Below is my collection data base and Query.



enter image description here



exports.authVerfication = functions.https.onRequest((req,res)=>{
if(req.method!=='POST'){
return res.status(500).json({
message:'Not allowed'
});
}

const p3= db.collection('Users').where('state', '==', 'Kar').get();
const p2= p3.then(snapshot =>{
if (!snapshot.exists) {
res.status(204).send({message:'No users found'});
} else {
res.status(200).send(snapshot.data());
}
})






javascript firebase google-cloud-firestore google-cloud-functions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 14:50









Frank van Puffelen

238k29382408




238k29382408










asked Nov 22 '18 at 13:30









Praveen Linge gowdaPraveen Linge gowda

363




363













  • What do you mean by "returning null". How do you display the results? In other words, what is after the .get()??

    – Renaud Tarnec
    Nov 22 '18 at 13:49













  • const p3= db.collection('Users').where('state', '==', 'Kar').get(); const p2= p3.then(snapshot =>{ if (!snapshot.exists) { res.status(204).send({message:'No users found'}); } else { res.status(200).send(snapshot.data()); } }) This is how i m returning an API results.

    – Praveen Linge gowda
    Nov 22 '18 at 13:50













  • Can you modify your original question with this part of the code? Thx

    – Renaud Tarnec
    Nov 22 '18 at 13:51











  • Yep, it works by adding doc.data() as you suggested. Thanks!

    – Praveen Linge gowda
    Nov 22 '18 at 14:10











  • Glad I could help. You may accept my answer by clicking on the grey checkmark next to the answer and turn it to green, see stackoverflow.com/help/someone-answers. Thanks.

    – Renaud Tarnec
    Nov 22 '18 at 14:38



















  • What do you mean by "returning null". How do you display the results? In other words, what is after the .get()??

    – Renaud Tarnec
    Nov 22 '18 at 13:49













  • const p3= db.collection('Users').where('state', '==', 'Kar').get(); const p2= p3.then(snapshot =>{ if (!snapshot.exists) { res.status(204).send({message:'No users found'}); } else { res.status(200).send(snapshot.data()); } }) This is how i m returning an API results.

    – Praveen Linge gowda
    Nov 22 '18 at 13:50













  • Can you modify your original question with this part of the code? Thx

    – Renaud Tarnec
    Nov 22 '18 at 13:51











  • Yep, it works by adding doc.data() as you suggested. Thanks!

    – Praveen Linge gowda
    Nov 22 '18 at 14:10











  • Glad I could help. You may accept my answer by clicking on the grey checkmark next to the answer and turn it to green, see stackoverflow.com/help/someone-answers. Thanks.

    – Renaud Tarnec
    Nov 22 '18 at 14:38

















What do you mean by "returning null". How do you display the results? In other words, what is after the .get()??

– Renaud Tarnec
Nov 22 '18 at 13:49







What do you mean by "returning null". How do you display the results? In other words, what is after the .get()??

– Renaud Tarnec
Nov 22 '18 at 13:49















const p3= db.collection('Users').where('state', '==', 'Kar').get(); const p2= p3.then(snapshot =>{ if (!snapshot.exists) { res.status(204).send({message:'No users found'}); } else { res.status(200).send(snapshot.data()); } }) This is how i m returning an API results.

– Praveen Linge gowda
Nov 22 '18 at 13:50







const p3= db.collection('Users').where('state', '==', 'Kar').get(); const p2= p3.then(snapshot =>{ if (!snapshot.exists) { res.status(204).send({message:'No users found'}); } else { res.status(200).send(snapshot.data()); } }) This is how i m returning an API results.

– Praveen Linge gowda
Nov 22 '18 at 13:50















Can you modify your original question with this part of the code? Thx

– Renaud Tarnec
Nov 22 '18 at 13:51





Can you modify your original question with this part of the code? Thx

– Renaud Tarnec
Nov 22 '18 at 13:51













Yep, it works by adding doc.data() as you suggested. Thanks!

– Praveen Linge gowda
Nov 22 '18 at 14:10





Yep, it works by adding doc.data() as you suggested. Thanks!

– Praveen Linge gowda
Nov 22 '18 at 14:10













Glad I could help. You may accept my answer by clicking on the grey checkmark next to the answer and turn it to green, see stackoverflow.com/help/someone-answers. Thanks.

– Renaud Tarnec
Nov 22 '18 at 14:38





Glad I could help. You may accept my answer by clicking on the grey checkmark next to the answer and turn it to green, see stackoverflow.com/help/someone-answers. Thanks.

– Renaud Tarnec
Nov 22 '18 at 14:38












1 Answer
1






active

oldest

votes


















2














By doing:



 const p3 = db.collection('Users').where('state', '==', 'Kar').get();
const p2 = p3.then(snapshot =>{})


the snapshot you get is a QuerySnapshot (see doc) and there is no exists property for such an object. You should use the empty property.





As said in a comment to your question (that I deleted) you can test that the query returns a result with:



const p3 = db.collection('Users').where('state', '==', 'Kar').get();
const p2 = p3.get()
.then(snapshot => {
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
})
.catch(err => {
console.log('Error getting documents', err);
});





share|improve this answer

























    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%2f53432099%2fcloud-firestore-search-by-child-value%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









    2














    By doing:



     const p3 = db.collection('Users').where('state', '==', 'Kar').get();
    const p2 = p3.then(snapshot =>{})


    the snapshot you get is a QuerySnapshot (see doc) and there is no exists property for such an object. You should use the empty property.





    As said in a comment to your question (that I deleted) you can test that the query returns a result with:



    const p3 = db.collection('Users').where('state', '==', 'Kar').get();
    const p2 = p3.get()
    .then(snapshot => {
    snapshot.forEach(doc => {
    console.log(doc.id, '=>', doc.data());
    });
    })
    .catch(err => {
    console.log('Error getting documents', err);
    });





    share|improve this answer






























      2














      By doing:



       const p3 = db.collection('Users').where('state', '==', 'Kar').get();
      const p2 = p3.then(snapshot =>{})


      the snapshot you get is a QuerySnapshot (see doc) and there is no exists property for such an object. You should use the empty property.





      As said in a comment to your question (that I deleted) you can test that the query returns a result with:



      const p3 = db.collection('Users').where('state', '==', 'Kar').get();
      const p2 = p3.get()
      .then(snapshot => {
      snapshot.forEach(doc => {
      console.log(doc.id, '=>', doc.data());
      });
      })
      .catch(err => {
      console.log('Error getting documents', err);
      });





      share|improve this answer




























        2












        2








        2







        By doing:



         const p3 = db.collection('Users').where('state', '==', 'Kar').get();
        const p2 = p3.then(snapshot =>{})


        the snapshot you get is a QuerySnapshot (see doc) and there is no exists property for such an object. You should use the empty property.





        As said in a comment to your question (that I deleted) you can test that the query returns a result with:



        const p3 = db.collection('Users').where('state', '==', 'Kar').get();
        const p2 = p3.get()
        .then(snapshot => {
        snapshot.forEach(doc => {
        console.log(doc.id, '=>', doc.data());
        });
        })
        .catch(err => {
        console.log('Error getting documents', err);
        });





        share|improve this answer















        By doing:



         const p3 = db.collection('Users').where('state', '==', 'Kar').get();
        const p2 = p3.then(snapshot =>{})


        the snapshot you get is a QuerySnapshot (see doc) and there is no exists property for such an object. You should use the empty property.





        As said in a comment to your question (that I deleted) you can test that the query returns a result with:



        const p3 = db.collection('Users').where('state', '==', 'Kar').get();
        const p2 = p3.get()
        .then(snapshot => {
        snapshot.forEach(doc => {
        console.log(doc.id, '=>', doc.data());
        });
        })
        .catch(err => {
        console.log('Error getting documents', err);
        });






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 14:39

























        answered Nov 22 '18 at 13:56









        Renaud TarnecRenaud Tarnec

        11.9k21532




        11.9k21532
































            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%2f53432099%2fcloud-firestore-search-by-child-value%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?