Mongo query to fetch selective fields from the collection [duplicate]
This question already has an answer here:
How to select a single field in MongoDB?
15 answers
Is it possible to fetch selective fields from mongo collections.
Say if my collections is
USer_info
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d5", "date":"2018-07-23T00:00:00.000Z", "Name":"ABC", "ID": "1234", "Subjects":"[Maths, Physics, Science, Music]"}
{"_id" : ObjectId("56e0a3a2d5hjhfjtaese45d5", "date":"2018-07-23T00:00:00.000Z", "Name":"BCS", "ID": "3456", "Subjects":"[CS, Physics, Business]"}
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d6", "date":"2018-07-23T00:00:00.000Z", "Name":"XYZ", "ID": "786", "Subjects": "[Agricultar, Business, Music]"}
Query to list only Name and SUbjects fields:
{"Name":"ABC", "Subjects":"[Maths, Physics, Science, Music]"}
{"Name":"BCS", "Subjects":"[CS, Physics, Business]"}
{"Name":"XYZ", "Subjects": "[Agricultar, Business, Music]"}
Not sure if this a duplicate, but i did not get anything similar so posting it.
mongodb mongodb-query pymongo
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 9:31
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to select a single field in MongoDB?
15 answers
Is it possible to fetch selective fields from mongo collections.
Say if my collections is
USer_info
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d5", "date":"2018-07-23T00:00:00.000Z", "Name":"ABC", "ID": "1234", "Subjects":"[Maths, Physics, Science, Music]"}
{"_id" : ObjectId("56e0a3a2d5hjhfjtaese45d5", "date":"2018-07-23T00:00:00.000Z", "Name":"BCS", "ID": "3456", "Subjects":"[CS, Physics, Business]"}
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d6", "date":"2018-07-23T00:00:00.000Z", "Name":"XYZ", "ID": "786", "Subjects": "[Agricultar, Business, Music]"}
Query to list only Name and SUbjects fields:
{"Name":"ABC", "Subjects":"[Maths, Physics, Science, Music]"}
{"Name":"BCS", "Subjects":"[CS, Physics, Business]"}
{"Name":"XYZ", "Subjects": "[Agricultar, Business, Music]"}
Not sure if this a duplicate, but i did not get anything similar so posting it.
mongodb mongodb-query pymongo
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 9:31
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to select a single field in MongoDB?
15 answers
Is it possible to fetch selective fields from mongo collections.
Say if my collections is
USer_info
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d5", "date":"2018-07-23T00:00:00.000Z", "Name":"ABC", "ID": "1234", "Subjects":"[Maths, Physics, Science, Music]"}
{"_id" : ObjectId("56e0a3a2d5hjhfjtaese45d5", "date":"2018-07-23T00:00:00.000Z", "Name":"BCS", "ID": "3456", "Subjects":"[CS, Physics, Business]"}
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d6", "date":"2018-07-23T00:00:00.000Z", "Name":"XYZ", "ID": "786", "Subjects": "[Agricultar, Business, Music]"}
Query to list only Name and SUbjects fields:
{"Name":"ABC", "Subjects":"[Maths, Physics, Science, Music]"}
{"Name":"BCS", "Subjects":"[CS, Physics, Business]"}
{"Name":"XYZ", "Subjects": "[Agricultar, Business, Music]"}
Not sure if this a duplicate, but i did not get anything similar so posting it.
mongodb mongodb-query pymongo
This question already has an answer here:
How to select a single field in MongoDB?
15 answers
Is it possible to fetch selective fields from mongo collections.
Say if my collections is
USer_info
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d5", "date":"2018-07-23T00:00:00.000Z", "Name":"ABC", "ID": "1234", "Subjects":"[Maths, Physics, Science, Music]"}
{"_id" : ObjectId("56e0a3a2d5hjhfjtaese45d5", "date":"2018-07-23T00:00:00.000Z", "Name":"BCS", "ID": "3456", "Subjects":"[CS, Physics, Business]"}
{"_id" : ObjectId("56e0a3a2d59feaa43fba49d6", "date":"2018-07-23T00:00:00.000Z", "Name":"XYZ", "ID": "786", "Subjects": "[Agricultar, Business, Music]"}
Query to list only Name and SUbjects fields:
{"Name":"ABC", "Subjects":"[Maths, Physics, Science, Music]"}
{"Name":"BCS", "Subjects":"[CS, Physics, Business]"}
{"Name":"XYZ", "Subjects": "[Agricultar, Business, Music]"}
Not sure if this a duplicate, but i did not get anything similar so posting it.
This question already has an answer here:
How to select a single field in MongoDB?
15 answers
mongodb mongodb-query pymongo
mongodb mongodb-query pymongo
asked Nov 21 '18 at 18:17
RachelRachel
949
949
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 9:31
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 9:31
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You have to define projection part of .find()
method to specify which fields should be returned. You alsow have to explicitly exclude _id, try:
col.find({}, { "_id": 0, "Name": 1, "Subjects": 1 })
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have to define projection part of .find()
method to specify which fields should be returned. You alsow have to explicitly exclude _id, try:
col.find({}, { "_id": 0, "Name": 1, "Subjects": 1 })
add a comment |
You have to define projection part of .find()
method to specify which fields should be returned. You alsow have to explicitly exclude _id, try:
col.find({}, { "_id": 0, "Name": 1, "Subjects": 1 })
add a comment |
You have to define projection part of .find()
method to specify which fields should be returned. You alsow have to explicitly exclude _id, try:
col.find({}, { "_id": 0, "Name": 1, "Subjects": 1 })
You have to define projection part of .find()
method to specify which fields should be returned. You alsow have to explicitly exclude _id, try:
col.find({}, { "_id": 0, "Name": 1, "Subjects": 1 })
answered Nov 21 '18 at 18:28
micklmickl
13.6k51536
13.6k51536
add a comment |
add a comment |