Identical queries in Mongoose and RoboMongo to the same database produce different results
I have some flight data in a mongodb and I'm trying to bring back each of the airline names and airline codes. There can be multiple records with the same airline name, so I just want it to come back once.
When I run the following query in RoboMongo(Robo3T) I correctly get back what I'm after.
db.getCollection('data').aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
])
The above returns records with both the airlineName and airlineCode grouped under _id.
When I run the following code in node/express. Only airlineCode is returned.
Airline.aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
]
node.js mongodb mongoose
add a comment |
I have some flight data in a mongodb and I'm trying to bring back each of the airline names and airline codes. There can be multiple records with the same airline name, so I just want it to come back once.
When I run the following query in RoboMongo(Robo3T) I correctly get back what I'm after.
db.getCollection('data').aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
])
The above returns records with both the airlineName and airlineCode grouped under _id.
When I run the following code in node/express. Only airlineCode is returned.
Airline.aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
]
node.js mongodb mongoose
2
Sorry to burst your bubble here, but there is literally no difference when using mongoose at all. So the only way you get different results is that in fact you're likely looking at different data sources. NotinggetCollection('data')
is not what anAirline = mongoose.model('Airline', new Schema({}))
is actually looking for by name of the collection. Mongoose is looking in theairlines
collection of whatever database you are actually connecting to.
– Neil Lunn
Nov 20 '18 at 9:38
1
Which basically translates to your data in the "completely different collection" has no property namedairlineName
, and as such nothing is returned. You probably typed the case differently into your mongoose schema. But still, "completely different collections" sorry.
– Neil Lunn
Nov 20 '18 at 9:41
1
Hi. Please dont apologise. I was thinking the same thing at first "how can it possibly return different results, it must be the data source!" but then after what i thought was a thorough check (obviously not thorough enough haha) I thought they were identical sources. Anyway after reading what you said I've noticed it straight away. I had 2 very similarly named datasources which confused me. I've now fixed the issue so thanks very much. Lesson learned, dont make the collections too similar!
– Cloudboy
Nov 20 '18 at 9:50
1
Dude they are not identical. Pay attention because that is what I am even showing you by example. Two completely different collections.
– Neil Lunn
Nov 20 '18 at 9:51
Sorry I pressed add comment before i finished typing. (thought pressing return would create a new line but it posted)
– Cloudboy
Nov 20 '18 at 9:52
add a comment |
I have some flight data in a mongodb and I'm trying to bring back each of the airline names and airline codes. There can be multiple records with the same airline name, so I just want it to come back once.
When I run the following query in RoboMongo(Robo3T) I correctly get back what I'm after.
db.getCollection('data').aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
])
The above returns records with both the airlineName and airlineCode grouped under _id.
When I run the following code in node/express. Only airlineCode is returned.
Airline.aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
]
node.js mongodb mongoose
I have some flight data in a mongodb and I'm trying to bring back each of the airline names and airline codes. There can be multiple records with the same airline name, so I just want it to come back once.
When I run the following query in RoboMongo(Robo3T) I correctly get back what I'm after.
db.getCollection('data').aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
])
The above returns records with both the airlineName and airlineCode grouped under _id.
When I run the following code in node/express. Only airlineCode is returned.
Airline.aggregate([
{
"$group": {
"_id": {
"airlineName": "$airlineName",
"airlineCode": "$airlineCode"
}
}
}
]
node.js mongodb mongoose
node.js mongodb mongoose
edited Nov 20 '18 at 9:39
Neil Lunn
97.5k23174184
97.5k23174184
asked Nov 20 '18 at 9:32
CloudboyCloudboy
13
13
2
Sorry to burst your bubble here, but there is literally no difference when using mongoose at all. So the only way you get different results is that in fact you're likely looking at different data sources. NotinggetCollection('data')
is not what anAirline = mongoose.model('Airline', new Schema({}))
is actually looking for by name of the collection. Mongoose is looking in theairlines
collection of whatever database you are actually connecting to.
– Neil Lunn
Nov 20 '18 at 9:38
1
Which basically translates to your data in the "completely different collection" has no property namedairlineName
, and as such nothing is returned. You probably typed the case differently into your mongoose schema. But still, "completely different collections" sorry.
– Neil Lunn
Nov 20 '18 at 9:41
1
Hi. Please dont apologise. I was thinking the same thing at first "how can it possibly return different results, it must be the data source!" but then after what i thought was a thorough check (obviously not thorough enough haha) I thought they were identical sources. Anyway after reading what you said I've noticed it straight away. I had 2 very similarly named datasources which confused me. I've now fixed the issue so thanks very much. Lesson learned, dont make the collections too similar!
– Cloudboy
Nov 20 '18 at 9:50
1
Dude they are not identical. Pay attention because that is what I am even showing you by example. Two completely different collections.
– Neil Lunn
Nov 20 '18 at 9:51
Sorry I pressed add comment before i finished typing. (thought pressing return would create a new line but it posted)
– Cloudboy
Nov 20 '18 at 9:52
add a comment |
2
Sorry to burst your bubble here, but there is literally no difference when using mongoose at all. So the only way you get different results is that in fact you're likely looking at different data sources. NotinggetCollection('data')
is not what anAirline = mongoose.model('Airline', new Schema({}))
is actually looking for by name of the collection. Mongoose is looking in theairlines
collection of whatever database you are actually connecting to.
– Neil Lunn
Nov 20 '18 at 9:38
1
Which basically translates to your data in the "completely different collection" has no property namedairlineName
, and as such nothing is returned. You probably typed the case differently into your mongoose schema. But still, "completely different collections" sorry.
– Neil Lunn
Nov 20 '18 at 9:41
1
Hi. Please dont apologise. I was thinking the same thing at first "how can it possibly return different results, it must be the data source!" but then after what i thought was a thorough check (obviously not thorough enough haha) I thought they were identical sources. Anyway after reading what you said I've noticed it straight away. I had 2 very similarly named datasources which confused me. I've now fixed the issue so thanks very much. Lesson learned, dont make the collections too similar!
– Cloudboy
Nov 20 '18 at 9:50
1
Dude they are not identical. Pay attention because that is what I am even showing you by example. Two completely different collections.
– Neil Lunn
Nov 20 '18 at 9:51
Sorry I pressed add comment before i finished typing. (thought pressing return would create a new line but it posted)
– Cloudboy
Nov 20 '18 at 9:52
2
2
Sorry to burst your bubble here, but there is literally no difference when using mongoose at all. So the only way you get different results is that in fact you're likely looking at different data sources. Noting
getCollection('data')
is not what an Airline = mongoose.model('Airline', new Schema({}))
is actually looking for by name of the collection. Mongoose is looking in the airlines
collection of whatever database you are actually connecting to.– Neil Lunn
Nov 20 '18 at 9:38
Sorry to burst your bubble here, but there is literally no difference when using mongoose at all. So the only way you get different results is that in fact you're likely looking at different data sources. Noting
getCollection('data')
is not what an Airline = mongoose.model('Airline', new Schema({}))
is actually looking for by name of the collection. Mongoose is looking in the airlines
collection of whatever database you are actually connecting to.– Neil Lunn
Nov 20 '18 at 9:38
1
1
Which basically translates to your data in the "completely different collection" has no property named
airlineName
, and as such nothing is returned. You probably typed the case differently into your mongoose schema. But still, "completely different collections" sorry.– Neil Lunn
Nov 20 '18 at 9:41
Which basically translates to your data in the "completely different collection" has no property named
airlineName
, and as such nothing is returned. You probably typed the case differently into your mongoose schema. But still, "completely different collections" sorry.– Neil Lunn
Nov 20 '18 at 9:41
1
1
Hi. Please dont apologise. I was thinking the same thing at first "how can it possibly return different results, it must be the data source!" but then after what i thought was a thorough check (obviously not thorough enough haha) I thought they were identical sources. Anyway after reading what you said I've noticed it straight away. I had 2 very similarly named datasources which confused me. I've now fixed the issue so thanks very much. Lesson learned, dont make the collections too similar!
– Cloudboy
Nov 20 '18 at 9:50
Hi. Please dont apologise. I was thinking the same thing at first "how can it possibly return different results, it must be the data source!" but then after what i thought was a thorough check (obviously not thorough enough haha) I thought they were identical sources. Anyway after reading what you said I've noticed it straight away. I had 2 very similarly named datasources which confused me. I've now fixed the issue so thanks very much. Lesson learned, dont make the collections too similar!
– Cloudboy
Nov 20 '18 at 9:50
1
1
Dude they are not identical. Pay attention because that is what I am even showing you by example. Two completely different collections.
– Neil Lunn
Nov 20 '18 at 9:51
Dude they are not identical. Pay attention because that is what I am even showing you by example. Two completely different collections.
– Neil Lunn
Nov 20 '18 at 9:51
Sorry I pressed add comment before i finished typing. (thought pressing return would create a new line but it posted)
– Cloudboy
Nov 20 '18 at 9:52
Sorry I pressed add comment before i finished typing. (thought pressing return would create a new line but it posted)
– Cloudboy
Nov 20 '18 at 9:52
add a comment |
0
active
oldest
votes
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%2f53389963%2fidentical-queries-in-mongoose-and-robomongo-to-the-same-database-produce-differe%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53389963%2fidentical-queries-in-mongoose-and-robomongo-to-the-same-database-produce-differe%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
2
Sorry to burst your bubble here, but there is literally no difference when using mongoose at all. So the only way you get different results is that in fact you're likely looking at different data sources. Noting
getCollection('data')
is not what anAirline = mongoose.model('Airline', new Schema({}))
is actually looking for by name of the collection. Mongoose is looking in theairlines
collection of whatever database you are actually connecting to.– Neil Lunn
Nov 20 '18 at 9:38
1
Which basically translates to your data in the "completely different collection" has no property named
airlineName
, and as such nothing is returned. You probably typed the case differently into your mongoose schema. But still, "completely different collections" sorry.– Neil Lunn
Nov 20 '18 at 9:41
1
Hi. Please dont apologise. I was thinking the same thing at first "how can it possibly return different results, it must be the data source!" but then after what i thought was a thorough check (obviously not thorough enough haha) I thought they were identical sources. Anyway after reading what you said I've noticed it straight away. I had 2 very similarly named datasources which confused me. I've now fixed the issue so thanks very much. Lesson learned, dont make the collections too similar!
– Cloudboy
Nov 20 '18 at 9:50
1
Dude they are not identical. Pay attention because that is what I am even showing you by example. Two completely different collections.
– Neil Lunn
Nov 20 '18 at 9:51
Sorry I pressed add comment before i finished typing. (thought pressing return would create a new line but it posted)
– Cloudboy
Nov 20 '18 at 9:52