Can i add a way to check if my find() function contains a parameter and the return documents with only the specific field?Checking if a field contains a stringApply function to field on all documents returned from MongoDB query in nodejsFind document with array that contains a specific valueMongoDB the most efficient way to query documents whose specific fields are not contained in a list of valuesMongoose add element to a document field that is an arrayMongoDB query to return documents that only have keys amongst a predefined setMongoDB Dinamically validate field in updateHow to query linked documents in mongodbhow to check if a field exists in a specific document Mongodb using C#?How to update only specific field on embedded file ini node js and mongodb

A non-technological, repeating, visible object in the sky, holding its position in the sky for hours

Can a cyclic Amine form an Amide?

Why was Germany not as successful as other Europeans in establishing overseas colonies?

Pigeonhole Principle Problem

Why do computer-science majors learn calculus?

How to efficiently calculate prefix sum of frequencies of characters in a string?

How to avoid grep command finding commented out strings in the source file?

Stark VS Thanos

Visualizing a complicated Region

Copy line and insert it in a new position with sed or awk

Who died in the Game of Thrones episode, "The Long Night"?

If I supply 24v to a 50v rated 22000uf electrolytic capacitor, does that mean it will store 44000uf at 24v?

Is lying to get "gardening leave" fraud?

Was Hulk present at this funeral?

Melee attacking upwards (enemy on 10ft ceiling)

Can I use 1000v rectifier diodes instead of 600v rectifier diodes?

If Melisandre foresaw another character closing blue eyes, why did she follow Stannis?

How long can a 35mm film be used/stored before it starts to lose its quality after expiry?

Accidentally deleted the "/usr/share" folder

Why do money exchangers give different rates to different bills

How to back up a running Linode server?

Why is Thanos so tough at the beginning of "Avengers: Endgame"?

How to reply this mail from potential PhD professor?

Is this homebrew race based on the Draco Volans lizard species balanced?



Can i add a way to check if my find() function contains a parameter and the return documents with only the specific field?


Checking if a field contains a stringApply function to field on all documents returned from MongoDB query in nodejsFind document with array that contains a specific valueMongoDB the most efficient way to query documents whose specific fields are not contained in a list of valuesMongoose add element to a document field that is an arrayMongoDB query to return documents that only have keys amongst a predefined setMongoDB Dinamically validate field in updateHow to query linked documents in mongodbhow to check if a field exists in a specific document Mongodb using C#?How to update only specific field on embedded file ini node js and mongodb






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















i would like to know if there is a way to check within the list_all function if there is a parameter and only then to check and return the documents which have a field with the requested parameter.



This is my controller code:



exports.list_all = function(req, res) 
Employees.find(function(err, list)
if (!err)
res.send(list);
else
res.send(err);

);
;


This is my endpoint:



 app.route("/employeesByStore/:storeId")
.get(Employees.list_all);
};


Thank you in advance.



UPDATE:



I finally applied the filter this way:



exports.list_all = function(req, res) 
Employees.find("storeId":req.params.storeId,function(err, list)
if (!err)
res.send(list);
else
res.send(err);

);










share|improve this question






























    0















    i would like to know if there is a way to check within the list_all function if there is a parameter and only then to check and return the documents which have a field with the requested parameter.



    This is my controller code:



    exports.list_all = function(req, res) 
    Employees.find(function(err, list)
    if (!err)
    res.send(list);
    else
    res.send(err);

    );
    ;


    This is my endpoint:



     app.route("/employeesByStore/:storeId")
    .get(Employees.list_all);
    };


    Thank you in advance.



    UPDATE:



    I finally applied the filter this way:



    exports.list_all = function(req, res) 
    Employees.find("storeId":req.params.storeId,function(err, list)
    if (!err)
    res.send(list);
    else
    res.send(err);

    );










    share|improve this question


























      0












      0








      0








      i would like to know if there is a way to check within the list_all function if there is a parameter and only then to check and return the documents which have a field with the requested parameter.



      This is my controller code:



      exports.list_all = function(req, res) 
      Employees.find(function(err, list)
      if (!err)
      res.send(list);
      else
      res.send(err);

      );
      ;


      This is my endpoint:



       app.route("/employeesByStore/:storeId")
      .get(Employees.list_all);
      };


      Thank you in advance.



      UPDATE:



      I finally applied the filter this way:



      exports.list_all = function(req, res) 
      Employees.find("storeId":req.params.storeId,function(err, list)
      if (!err)
      res.send(list);
      else
      res.send(err);

      );










      share|improve this question
















      i would like to know if there is a way to check within the list_all function if there is a parameter and only then to check and return the documents which have a field with the requested parameter.



      This is my controller code:



      exports.list_all = function(req, res) 
      Employees.find(function(err, list)
      if (!err)
      res.send(list);
      else
      res.send(err);

      );
      ;


      This is my endpoint:



       app.route("/employeesByStore/:storeId")
      .get(Employees.list_all);
      };


      Thank you in advance.



      UPDATE:



      I finally applied the filter this way:



      exports.list_all = function(req, res) 
      Employees.find("storeId":req.params.storeId,function(err, list)
      if (!err)
      res.send(list);
      else
      res.send(err);

      );







      node.js mongodb express mongoose






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 8:34







      user3267020

















      asked Mar 22 at 20:08









      user3267020user3267020

      284




      284






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can try something like this :



          exports.list_all = function(req, res) 
          if(Object.keys(req.params).length === 0)
          // no params passed, do something
          return;

          // a param is passed, let's query
          Employees.find(req.params, function(err, list)
          if (!err)
          res.send(list);
          else
          res.send(err);

          );
          ;


          req.params will contains something like storeId: "1234"






          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%2f55307114%2fcan-i-add-a-way-to-check-if-my-find-function-contains-a-parameter-and-the-retu%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














            You can try something like this :



            exports.list_all = function(req, res) 
            if(Object.keys(req.params).length === 0)
            // no params passed, do something
            return;

            // a param is passed, let's query
            Employees.find(req.params, function(err, list)
            if (!err)
            res.send(list);
            else
            res.send(err);

            );
            ;


            req.params will contains something like storeId: "1234"






            share|improve this answer



























              0














              You can try something like this :



              exports.list_all = function(req, res) 
              if(Object.keys(req.params).length === 0)
              // no params passed, do something
              return;

              // a param is passed, let's query
              Employees.find(req.params, function(err, list)
              if (!err)
              res.send(list);
              else
              res.send(err);

              );
              ;


              req.params will contains something like storeId: "1234"






              share|improve this answer

























                0












                0








                0







                You can try something like this :



                exports.list_all = function(req, res) 
                if(Object.keys(req.params).length === 0)
                // no params passed, do something
                return;

                // a param is passed, let's query
                Employees.find(req.params, function(err, list)
                if (!err)
                res.send(list);
                else
                res.send(err);

                );
                ;


                req.params will contains something like storeId: "1234"






                share|improve this answer













                You can try something like this :



                exports.list_all = function(req, res) 
                if(Object.keys(req.params).length === 0)
                // no params passed, do something
                return;

                // a param is passed, let's query
                Employees.find(req.params, function(err, list)
                if (!err)
                res.send(list);
                else
                res.send(err);

                );
                ;


                req.params will contains something like storeId: "1234"







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 20:21









                Julien TASSINJulien TASSIN

                2,2741823




                2,2741823





























                    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%2f55307114%2fcan-i-add-a-way-to-check-if-my-find-function-contains-a-parameter-and-the-retu%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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해