How do I list all documents in a collection but show a single property?
up vote
0
down vote
favorite
How do I list all documents in a collection but show a single property through a console window?
//Trying to just show name property
db.mycollection.find(name);
mongodb
add a comment |
up vote
0
down vote
favorite
How do I list all documents in a collection but show a single property through a console window?
//Trying to just show name property
db.mycollection.find(name);
mongodb
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How do I list all documents in a collection but show a single property through a console window?
//Trying to just show name property
db.mycollection.find(name);
mongodb
How do I list all documents in a collection but show a single property through a console window?
//Trying to just show name property
db.mycollection.find(name);
mongodb
mongodb
asked Nov 9 at 20:30
Rod
5,5551775135
5,5551775135
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
The find
mongo command accepts 2 parameters:
db.collection.find(query, projection)
query (Optional):
Specifies selection filter using query operators. To return all
documents in a collection, omit this parameter or pass an empty
document ().
projection (Optional):
Specifies the fields to return in the documents that match the query
filter. To return all fields in the matching documents, omit this
parameter. For details, see Projection.
In your scenario you have to use the projection parameter to specify which fields to be returned as so:
db.mycollection.find(, _id: 0, name: 1);
Since you do not care about providing criteria you can just leave that as empty object.
The _id: 0, name: 1
means that you do not want the default _id
field included in the results and only care/want the name
field.
2
"jinx" 8 second difference when I answered but you gave extra insight
– Rod
Nov 9 at 21:18
add a comment |
up vote
3
down vote
You can set your showing propertys this way:
db.mycollection.find(name:name, _id:0, name:1);
It will only show the name and hide the _id
add a comment |
up vote
0
down vote
db.mycollection.find(, _id:0, name: 1)
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The find
mongo command accepts 2 parameters:
db.collection.find(query, projection)
query (Optional):
Specifies selection filter using query operators. To return all
documents in a collection, omit this parameter or pass an empty
document ().
projection (Optional):
Specifies the fields to return in the documents that match the query
filter. To return all fields in the matching documents, omit this
parameter. For details, see Projection.
In your scenario you have to use the projection parameter to specify which fields to be returned as so:
db.mycollection.find(, _id: 0, name: 1);
Since you do not care about providing criteria you can just leave that as empty object.
The _id: 0, name: 1
means that you do not want the default _id
field included in the results and only care/want the name
field.
2
"jinx" 8 second difference when I answered but you gave extra insight
– Rod
Nov 9 at 21:18
add a comment |
up vote
1
down vote
accepted
The find
mongo command accepts 2 parameters:
db.collection.find(query, projection)
query (Optional):
Specifies selection filter using query operators. To return all
documents in a collection, omit this parameter or pass an empty
document ().
projection (Optional):
Specifies the fields to return in the documents that match the query
filter. To return all fields in the matching documents, omit this
parameter. For details, see Projection.
In your scenario you have to use the projection parameter to specify which fields to be returned as so:
db.mycollection.find(, _id: 0, name: 1);
Since you do not care about providing criteria you can just leave that as empty object.
The _id: 0, name: 1
means that you do not want the default _id
field included in the results and only care/want the name
field.
2
"jinx" 8 second difference when I answered but you gave extra insight
– Rod
Nov 9 at 21:18
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The find
mongo command accepts 2 parameters:
db.collection.find(query, projection)
query (Optional):
Specifies selection filter using query operators. To return all
documents in a collection, omit this parameter or pass an empty
document ().
projection (Optional):
Specifies the fields to return in the documents that match the query
filter. To return all fields in the matching documents, omit this
parameter. For details, see Projection.
In your scenario you have to use the projection parameter to specify which fields to be returned as so:
db.mycollection.find(, _id: 0, name: 1);
Since you do not care about providing criteria you can just leave that as empty object.
The _id: 0, name: 1
means that you do not want the default _id
field included in the results and only care/want the name
field.
The find
mongo command accepts 2 parameters:
db.collection.find(query, projection)
query (Optional):
Specifies selection filter using query operators. To return all
documents in a collection, omit this parameter or pass an empty
document ().
projection (Optional):
Specifies the fields to return in the documents that match the query
filter. To return all fields in the matching documents, omit this
parameter. For details, see Projection.
In your scenario you have to use the projection parameter to specify which fields to be returned as so:
db.mycollection.find(, _id: 0, name: 1);
Since you do not care about providing criteria you can just leave that as empty object.
The _id: 0, name: 1
means that you do not want the default _id
field included in the results and only care/want the name
field.
edited Nov 9 at 21:20
answered Nov 9 at 21:16
Akrion
7,10111222
7,10111222
2
"jinx" 8 second difference when I answered but you gave extra insight
– Rod
Nov 9 at 21:18
add a comment |
2
"jinx" 8 second difference when I answered but you gave extra insight
– Rod
Nov 9 at 21:18
2
2
"jinx" 8 second difference when I answered but you gave extra insight
– Rod
Nov 9 at 21:18
"jinx" 8 second difference when I answered but you gave extra insight
– Rod
Nov 9 at 21:18
add a comment |
up vote
3
down vote
You can set your showing propertys this way:
db.mycollection.find(name:name, _id:0, name:1);
It will only show the name and hide the _id
add a comment |
up vote
3
down vote
You can set your showing propertys this way:
db.mycollection.find(name:name, _id:0, name:1);
It will only show the name and hide the _id
add a comment |
up vote
3
down vote
up vote
3
down vote
You can set your showing propertys this way:
db.mycollection.find(name:name, _id:0, name:1);
It will only show the name and hide the _id
You can set your showing propertys this way:
db.mycollection.find(name:name, _id:0, name:1);
It will only show the name and hide the _id
answered Nov 9 at 20:32
KeeyPee
734
734
add a comment |
add a comment |
up vote
0
down vote
db.mycollection.find(, _id:0, name: 1)
add a comment |
up vote
0
down vote
db.mycollection.find(, _id:0, name: 1)
add a comment |
up vote
0
down vote
up vote
0
down vote
db.mycollection.find(, _id:0, name: 1)
db.mycollection.find(, _id:0, name: 1)
answered Nov 9 at 21:16
Rod
5,5551775135
5,5551775135
add a comment |
add a comment |
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%2f53232869%2fhow-do-i-list-all-documents-in-a-collection-but-show-a-single-property%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