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;
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
add a comment |
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
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
add a comment |
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
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
python mongodb
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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.
add a 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%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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 24 at 11:27
Joe DrumgooleJoe Drumgoole
995
995
add a comment |
add a 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%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
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
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