I want to get required documents but it seems to return every document of the collectionHow to return multiple values from a function?Can't subtract offset-naive and offset-aware datetimesHow do I run all Python unit tests in a directory?How do I perform the SQL Join equivalent in MongoDB?Peak detection in a 2D arrayWays to implement data versioning in MongoDBHow to make an unaware datetime timezone aware in pythonAdd new field to every document in a MongoDB collectionHow can I replace all the NaN values with Zero's in a column of a pandas dataframe“Large data” work flows using pandas

A curve pass via points at TiKz

How are one-time password generators like Google Authenticator different from having two passwords?

51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?

Why does my circuit work on a breadboard, but not on a perfboard? I am new to soldering

Reaction of borax with NaOH

How do I tell my supervisor that he is choosing poor replacements for me while I am on maternity leave?

Light Switch Terminals

What is the significance of 4200 BCE in context of farming replacing foraging in Europe?

What is the relation between semi-supervised self-supervised visual representation learning?

Does kinetic energy warp spacetime?

What happens if a creature that would fight isn't on the battlefield anymore?

How can a Lich look like a human without magic?

Can I use my laptop, which says 100-240V, in the USA?

Why was castling bad for white in this game, and engine strongly prefered trading queens?

Is there ever any indication in the MCU as to how Spider-Man got his powers?

Is it a bad idea to replace pull-up resistors with hard pull-ups?

Drawing lines to nearest point

What is the best way for a skeleton to impersonate human without using magic?

What does the expression "right on the tip of my tongue" mean?

How to get reference to Component from inside an event method

Exclude loop* snap devices from lsblk output?

Create a list of all possible Boolean configurations of three constraints

How to slow yourself down (for playing nice with others)

Why not just directly invest in the holdings of an ETF?



I want to get required documents but it seems to return every document of the collection


How to return multiple values from a function?Can't subtract offset-naive and offset-aware datetimesHow do I run all Python unit tests in a directory?How do I perform the SQL Join equivalent in MongoDB?Peak detection in a 2D arrayWays to implement data versioning in MongoDBHow to make an unaware datetime timezone aware in pythonAdd new field to every document in a MongoDB collectionHow can I replace all the NaN values with Zero's in a column of a pandas dataframe“Large data” work flows using pandas






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








0















I want to display the data with category doctor but I seem to get all the data.



I have tried using: result=db.find(,"first_name": 1, "last_name": 1, "cat": 'doctor') but still I get the wrong result.



@app.route("/users/get_doctors", methods = ['GET'])
def get_doctors():
try:
db = mongo.db.Login_Details
result=db.find(,"first_name": 1, "last_name": 1, "cat":
'doctor')
doctors = []
for dr in result:
doctors.append("first_name": dr['first_name'], "last_name" :
dr['last_name'], "cat" : dr['cat'])
return jsonify(doctors)
except Exception:
return 'error'









share|improve this question






















  • I think you're passing an empty dict (i.e. ) to the find method

    – BMW
    Mar 23 at 11:42











  • I have tried this result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat']) and also this result = db.find('cat': 'doctor', 'first_name', 'last_name', 'cat') but, still not working

    – Maisum
    Mar 24 at 8:22


















0















I want to display the data with category doctor but I seem to get all the data.



I have tried using: result=db.find(,"first_name": 1, "last_name": 1, "cat": 'doctor') but still I get the wrong result.



@app.route("/users/get_doctors", methods = ['GET'])
def get_doctors():
try:
db = mongo.db.Login_Details
result=db.find(,"first_name": 1, "last_name": 1, "cat":
'doctor')
doctors = []
for dr in result:
doctors.append("first_name": dr['first_name'], "last_name" :
dr['last_name'], "cat" : dr['cat'])
return jsonify(doctors)
except Exception:
return 'error'









share|improve this question






















  • I think you're passing an empty dict (i.e. ) to the find method

    – BMW
    Mar 23 at 11:42











  • I have tried this result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat']) and also this result = db.find('cat': 'doctor', 'first_name', 'last_name', 'cat') but, still not working

    – Maisum
    Mar 24 at 8:22














0












0








0








I want to display the data with category doctor but I seem to get all the data.



I have tried using: result=db.find(,"first_name": 1, "last_name": 1, "cat": 'doctor') but still I get the wrong result.



@app.route("/users/get_doctors", methods = ['GET'])
def get_doctors():
try:
db = mongo.db.Login_Details
result=db.find(,"first_name": 1, "last_name": 1, "cat":
'doctor')
doctors = []
for dr in result:
doctors.append("first_name": dr['first_name'], "last_name" :
dr['last_name'], "cat" : dr['cat'])
return jsonify(doctors)
except Exception:
return 'error'









share|improve this question














I want to display the data with category doctor but I seem to get all the data.



I have tried using: result=db.find(,"first_name": 1, "last_name": 1, "cat": 'doctor') but still I get the wrong result.



@app.route("/users/get_doctors", methods = ['GET'])
def get_doctors():
try:
db = mongo.db.Login_Details
result=db.find(,"first_name": 1, "last_name": 1, "cat":
'doctor')
doctors = []
for dr in result:
doctors.append("first_name": dr['first_name'], "last_name" :
dr['last_name'], "cat" : dr['cat'])
return jsonify(doctors)
except Exception:
return 'error'






python mongodb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 11:34









MaisumMaisum

45




45












  • I think you're passing an empty dict (i.e. ) to the find method

    – BMW
    Mar 23 at 11:42











  • I have tried this result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat']) and also this result = db.find('cat': 'doctor', 'first_name', 'last_name', 'cat') but, still not working

    – Maisum
    Mar 24 at 8:22


















  • I think you're passing an empty dict (i.e. ) to the find method

    – BMW
    Mar 23 at 11:42











  • I have tried this result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat']) and also this result = db.find('cat': 'doctor', 'first_name', 'last_name', 'cat') but, still not working

    – Maisum
    Mar 24 at 8:22

















I think you're passing an empty dict (i.e. ) to the find method

– BMW
Mar 23 at 11:42





I think you're passing an empty dict (i.e. ) to the find method

– BMW
Mar 23 at 11:42













I have tried this result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat']) and also this result = db.find('cat': 'doctor', 'first_name', 'last_name', 'cat') but, still not working

– Maisum
Mar 24 at 8:22






I have tried this result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat']) and also this result = db.find('cat': 'doctor', 'first_name', 'last_name', 'cat') but, still not working

– Maisum
Mar 24 at 8:22













2 Answers
2






active

oldest

votes


















0














This is because you are trying to combine filter and projection which is incorrect. Per MongoDB docs the first argument is filter and the second one is projection (which you may or may not need).



# Thi result contain all document with category doctor. Only first name,
# last name and category are retrieved.
result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat'])


The above example takes two arguments: the first one is a filter which is something like WHERE clausule in an ordinary SQL and the second argument is projection which lists fields which are going to be retrieved.






share|improve this answer

























  • I have tried it but there seems to be some syntax issue I believe due to which it does not work.

    – Maisum
    Mar 23 at 11:51











  • I've fixed a typo in the code sample (dp -> db). It should work now.

    – Martin Indra
    Mar 23 at 11:54











  • There seems to be some other problem other than this. I have fixed the typo already in the code.

    – Maisum
    Mar 23 at 12:01


















0














db.find( "cat" : "doctor" )


Will find all documents with cat = doctor.



db.find("cat": "doctor", "first_name": 1, "last_name": 1)


Will find all documents with cat = doctor. It will then only output the first_name and last_name fields. It will also output the _id field unless this explicitly suppressed by "_id": 0, "first_name": 1, "last_name": 1. The second argument defines the projection of the fields i.e. what fields will appear in the output.



See mongodb find for details on the syntax for queries and projections.






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%2f55313310%2fi-want-to-get-required-documents-but-it-seems-to-return-every-document-of-the-co%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This is because you are trying to combine filter and projection which is incorrect. Per MongoDB docs the first argument is filter and the second one is projection (which you may or may not need).



    # Thi result contain all document with category doctor. Only first name,
    # last name and category are retrieved.
    result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat'])


    The above example takes two arguments: the first one is a filter which is something like WHERE clausule in an ordinary SQL and the second argument is projection which lists fields which are going to be retrieved.






    share|improve this answer

























    • I have tried it but there seems to be some syntax issue I believe due to which it does not work.

      – Maisum
      Mar 23 at 11:51











    • I've fixed a typo in the code sample (dp -> db). It should work now.

      – Martin Indra
      Mar 23 at 11:54











    • There seems to be some other problem other than this. I have fixed the typo already in the code.

      – Maisum
      Mar 23 at 12:01















    0














    This is because you are trying to combine filter and projection which is incorrect. Per MongoDB docs the first argument is filter and the second one is projection (which you may or may not need).



    # Thi result contain all document with category doctor. Only first name,
    # last name and category are retrieved.
    result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat'])


    The above example takes two arguments: the first one is a filter which is something like WHERE clausule in an ordinary SQL and the second argument is projection which lists fields which are going to be retrieved.






    share|improve this answer

























    • I have tried it but there seems to be some syntax issue I believe due to which it does not work.

      – Maisum
      Mar 23 at 11:51











    • I've fixed a typo in the code sample (dp -> db). It should work now.

      – Martin Indra
      Mar 23 at 11:54











    • There seems to be some other problem other than this. I have fixed the typo already in the code.

      – Maisum
      Mar 23 at 12:01













    0












    0








    0







    This is because you are trying to combine filter and projection which is incorrect. Per MongoDB docs the first argument is filter and the second one is projection (which you may or may not need).



    # Thi result contain all document with category doctor. Only first name,
    # last name and category are retrieved.
    result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat'])


    The above example takes two arguments: the first one is a filter which is something like WHERE clausule in an ordinary SQL and the second argument is projection which lists fields which are going to be retrieved.






    share|improve this answer















    This is because you are trying to combine filter and projection which is incorrect. Per MongoDB docs the first argument is filter and the second one is projection (which you may or may not need).



    # Thi result contain all document with category doctor. Only first name,
    # last name and category are retrieved.
    result = db.find('cat': 'doctor', ['first_name', 'last_name', 'cat'])


    The above example takes two arguments: the first one is a filter which is something like WHERE clausule in an ordinary SQL and the second argument is projection which lists fields which are going to be retrieved.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 23 at 11:53

























    answered Mar 23 at 11:41









    Martin IndraMartin Indra

    1264




    1264












    • I have tried it but there seems to be some syntax issue I believe due to which it does not work.

      – Maisum
      Mar 23 at 11:51











    • I've fixed a typo in the code sample (dp -> db). It should work now.

      – Martin Indra
      Mar 23 at 11:54











    • There seems to be some other problem other than this. I have fixed the typo already in the code.

      – Maisum
      Mar 23 at 12:01

















    • I have tried it but there seems to be some syntax issue I believe due to which it does not work.

      – Maisum
      Mar 23 at 11:51











    • I've fixed a typo in the code sample (dp -> db). It should work now.

      – Martin Indra
      Mar 23 at 11:54











    • There seems to be some other problem other than this. I have fixed the typo already in the code.

      – Maisum
      Mar 23 at 12:01
















    I have tried it but there seems to be some syntax issue I believe due to which it does not work.

    – Maisum
    Mar 23 at 11:51





    I have tried it but there seems to be some syntax issue I believe due to which it does not work.

    – Maisum
    Mar 23 at 11:51













    I've fixed a typo in the code sample (dp -> db). It should work now.

    – Martin Indra
    Mar 23 at 11:54





    I've fixed a typo in the code sample (dp -> db). It should work now.

    – Martin Indra
    Mar 23 at 11:54













    There seems to be some other problem other than this. I have fixed the typo already in the code.

    – Maisum
    Mar 23 at 12:01





    There seems to be some other problem other than this. I have fixed the typo already in the code.

    – Maisum
    Mar 23 at 12:01













    0














    db.find( "cat" : "doctor" )


    Will find all documents with cat = doctor.



    db.find("cat": "doctor", "first_name": 1, "last_name": 1)


    Will find all documents with cat = doctor. It will then only output the first_name and last_name fields. It will also output the _id field unless this explicitly suppressed by "_id": 0, "first_name": 1, "last_name": 1. The second argument defines the projection of the fields i.e. what fields will appear in the output.



    See mongodb find for details on the syntax for queries and projections.






    share|improve this answer



























      0














      db.find( "cat" : "doctor" )


      Will find all documents with cat = doctor.



      db.find("cat": "doctor", "first_name": 1, "last_name": 1)


      Will find all documents with cat = doctor. It will then only output the first_name and last_name fields. It will also output the _id field unless this explicitly suppressed by "_id": 0, "first_name": 1, "last_name": 1. The second argument defines the projection of the fields i.e. what fields will appear in the output.



      See mongodb find for details on the syntax for queries and projections.






      share|improve this answer

























        0












        0








        0







        db.find( "cat" : "doctor" )


        Will find all documents with cat = doctor.



        db.find("cat": "doctor", "first_name": 1, "last_name": 1)


        Will find all documents with cat = doctor. It will then only output the first_name and last_name fields. It will also output the _id field unless this explicitly suppressed by "_id": 0, "first_name": 1, "last_name": 1. The second argument defines the projection of the fields i.e. what fields will appear in the output.



        See mongodb find for details on the syntax for queries and projections.






        share|improve this answer













        db.find( "cat" : "doctor" )


        Will find all documents with cat = doctor.



        db.find("cat": "doctor", "first_name": 1, "last_name": 1)


        Will find all documents with cat = doctor. It will then only output the first_name and last_name fields. It will also output the _id field unless this explicitly suppressed by "_id": 0, "first_name": 1, "last_name": 1. The second argument defines the projection of the fields i.e. what fields will appear in the output.



        See mongodb find for details on the syntax for queries and projections.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 11:27









        Joe DrumgooleJoe Drumgoole

        995




        995



























            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%2f55313310%2fi-want-to-get-required-documents-but-it-seems-to-return-every-document-of-the-co%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            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

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현