Make many populate in deep populate, 2nd levelHow to achieve DBRef on virtualHandle CastError with Mongoose using PromisesWhy is Model.save() not working in Sails.js?Mongoose save() returns before findOne()Is populate implicit and how many levels deep can it go?Node, Mongoose js - Populate never returning a resultMongoose refuses to cast valid string to ObjectIdMongoose deep populate results in [Object] at 2nd levelHandling mongoose population exceptionsMongoose populate sort option
How were these pictures of spacecraft wind tunnel testing taken?
1960s sci-fi novella with a character who is treated as invisible by being ignored
Smart people send dumb people to a new planet on a space craft that crashes into a body of water
Future enhancements for the finite element method
Crossing US border with music files I'm legally allowed to possess
Transform the partial differential equation with new independent variables
Glitch in AC sine wave interfering with phase cut dimming
Comment dit-on « I’ll tell you what » ?
Yandex Programming Contest: Alarms
Could I be denied entry into Ireland due to medical and police situations during a previous UK visit?
What does the behaviour of water on the skin of an aircraft in flight tell us?
What are the benefits of cryosleep?
Is it ok to put a subplot to a story that is never meant to contribute to the development of the main plot?
Why doesn't the Earth's acceleration towards the Moon accumulate to push the Earth off its orbit?
The Passive Wisdom (Perception) score of my character on D&D Beyond seems too high
Were pen cap holes designed to prevent death by suffocation if swallowed?
Leading and Suffering Numbers
How does apt-get work, in detail?
What is the best linguistic term for describing the kw > p / gw > b change, and its usual companion s > h
Crossword gone overboard
Draw a checker pattern with a black X in the center
Why does the UK have more political parties than the US?
How to extract lower and upper bound in numeric format from a confidence interval string?
What caused the tendency for conservatives to not support climate change reform?
Make many populate in deep populate, 2nd level
How to achieve DBRef on virtualHandle CastError with Mongoose using PromisesWhy is Model.save() not working in Sails.js?Mongoose save() returns before findOne()Is populate implicit and how many levels deep can it go?Node, Mongoose js - Populate never returning a resultMongoose refuses to cast valid string to ObjectIdMongoose deep populate results in [Object] at 2nd levelHandling mongoose population exceptionsMongoose populate sort option
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am doing a query of nested objects using populate and when wanting to access a population of the second level, it does not recognize me if not the last population
I'm working under nodejs and mongodb, using the mongoose library
For the population of 'tours_favoritos' only recognizes me the last: 'guia' with its population of 'idiomas'. I do not populate 'sitios', nor 'turistas', nor 'categoria', nor 'empresa_turismo'. If I change the order of the population, only the last one populates me.
servicev1.addGustoFavorito = function (id_turista, id_gusto)
return new Promise(function (resolve, reject)
GustoTurista.findById(id_gusto, function (error, gusto)
if (!error)
var query = Turista.findByIdAndUpdate(id_turista, $push: gustos: gusto._id , new: true );
query.
populate(
path: 'empresas_favoritas', model: EmpresaTurismo
).
populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
).
populate(
path: 'gustos', model: GustoTurista
)
.exec(function (err, success)
if (err)
return reject(err);
else
return resolve(success);
)
else
return reject(error);
)
)
See code
node.js mongodb mongoose mongoose-schema mongoose-populate
add a comment |
I am doing a query of nested objects using populate and when wanting to access a population of the second level, it does not recognize me if not the last population
I'm working under nodejs and mongodb, using the mongoose library
For the population of 'tours_favoritos' only recognizes me the last: 'guia' with its population of 'idiomas'. I do not populate 'sitios', nor 'turistas', nor 'categoria', nor 'empresa_turismo'. If I change the order of the population, only the last one populates me.
servicev1.addGustoFavorito = function (id_turista, id_gusto)
return new Promise(function (resolve, reject)
GustoTurista.findById(id_gusto, function (error, gusto)
if (!error)
var query = Turista.findByIdAndUpdate(id_turista, $push: gustos: gusto._id , new: true );
query.
populate(
path: 'empresas_favoritas', model: EmpresaTurismo
).
populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
).
populate(
path: 'gustos', model: GustoTurista
)
.exec(function (err, success)
if (err)
return reject(err);
else
return resolve(success);
)
else
return reject(error);
)
)
See code
node.js mongodb mongoose mongoose-schema mongoose-populate
1
The problem here is that without any knowledge of how the models actually interrelate and what the expected result would be we cannot determine what would be wrong with what you are doing. You would basically need to show sample data from each model that would be expected to be retrieved by all of thepopulate()
calls. The real big problem here though is that's a lot of joins and MongoDB just is not designed to be used like that. Furthermore you probably do not realize that every time you typepopulate
that is effectively another query to the server. I count 11 requests here.
– Neil Lunn
Mar 24 at 9:13
1
Basically 11 requests to the server ( eachfindBy
and every mention onpopulate
) just to return some data on a page is extremely excessive and will cause major performance problems for you ongoing. You really need to redesign this since you are still thinking far too much in relational terms.$lookup
can help by making that one request, but the "joins" are still a significant overhead here.
– Neil Lunn
Mar 24 at 9:15
add a comment |
I am doing a query of nested objects using populate and when wanting to access a population of the second level, it does not recognize me if not the last population
I'm working under nodejs and mongodb, using the mongoose library
For the population of 'tours_favoritos' only recognizes me the last: 'guia' with its population of 'idiomas'. I do not populate 'sitios', nor 'turistas', nor 'categoria', nor 'empresa_turismo'. If I change the order of the population, only the last one populates me.
servicev1.addGustoFavorito = function (id_turista, id_gusto)
return new Promise(function (resolve, reject)
GustoTurista.findById(id_gusto, function (error, gusto)
if (!error)
var query = Turista.findByIdAndUpdate(id_turista, $push: gustos: gusto._id , new: true );
query.
populate(
path: 'empresas_favoritas', model: EmpresaTurismo
).
populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
).
populate(
path: 'gustos', model: GustoTurista
)
.exec(function (err, success)
if (err)
return reject(err);
else
return resolve(success);
)
else
return reject(error);
)
)
See code
node.js mongodb mongoose mongoose-schema mongoose-populate
I am doing a query of nested objects using populate and when wanting to access a population of the second level, it does not recognize me if not the last population
I'm working under nodejs and mongodb, using the mongoose library
For the population of 'tours_favoritos' only recognizes me the last: 'guia' with its population of 'idiomas'. I do not populate 'sitios', nor 'turistas', nor 'categoria', nor 'empresa_turismo'. If I change the order of the population, only the last one populates me.
servicev1.addGustoFavorito = function (id_turista, id_gusto)
return new Promise(function (resolve, reject)
GustoTurista.findById(id_gusto, function (error, gusto)
if (!error)
var query = Turista.findByIdAndUpdate(id_turista, $push: gustos: gusto._id , new: true );
query.
populate(
path: 'empresas_favoritas', model: EmpresaTurismo
).
populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
).
populate(
path: 'gustos', model: GustoTurista
)
.exec(function (err, success)
if (err)
return reject(err);
else
return resolve(success);
)
else
return reject(error);
)
)
See code
node.js mongodb mongoose mongoose-schema mongoose-populate
node.js mongodb mongoose mongoose-schema mongoose-populate
edited Mar 24 at 8:51
WI HERMES
asked Mar 24 at 8:44
WI HERMESWI HERMES
11
11
1
The problem here is that without any knowledge of how the models actually interrelate and what the expected result would be we cannot determine what would be wrong with what you are doing. You would basically need to show sample data from each model that would be expected to be retrieved by all of thepopulate()
calls. The real big problem here though is that's a lot of joins and MongoDB just is not designed to be used like that. Furthermore you probably do not realize that every time you typepopulate
that is effectively another query to the server. I count 11 requests here.
– Neil Lunn
Mar 24 at 9:13
1
Basically 11 requests to the server ( eachfindBy
and every mention onpopulate
) just to return some data on a page is extremely excessive and will cause major performance problems for you ongoing. You really need to redesign this since you are still thinking far too much in relational terms.$lookup
can help by making that one request, but the "joins" are still a significant overhead here.
– Neil Lunn
Mar 24 at 9:15
add a comment |
1
The problem here is that without any knowledge of how the models actually interrelate and what the expected result would be we cannot determine what would be wrong with what you are doing. You would basically need to show sample data from each model that would be expected to be retrieved by all of thepopulate()
calls. The real big problem here though is that's a lot of joins and MongoDB just is not designed to be used like that. Furthermore you probably do not realize that every time you typepopulate
that is effectively another query to the server. I count 11 requests here.
– Neil Lunn
Mar 24 at 9:13
1
Basically 11 requests to the server ( eachfindBy
and every mention onpopulate
) just to return some data on a page is extremely excessive and will cause major performance problems for you ongoing. You really need to redesign this since you are still thinking far too much in relational terms.$lookup
can help by making that one request, but the "joins" are still a significant overhead here.
– Neil Lunn
Mar 24 at 9:15
1
1
The problem here is that without any knowledge of how the models actually interrelate and what the expected result would be we cannot determine what would be wrong with what you are doing. You would basically need to show sample data from each model that would be expected to be retrieved by all of the
populate()
calls. The real big problem here though is that's a lot of joins and MongoDB just is not designed to be used like that. Furthermore you probably do not realize that every time you type populate
that is effectively another query to the server. I count 11 requests here.– Neil Lunn
Mar 24 at 9:13
The problem here is that without any knowledge of how the models actually interrelate and what the expected result would be we cannot determine what would be wrong with what you are doing. You would basically need to show sample data from each model that would be expected to be retrieved by all of the
populate()
calls. The real big problem here though is that's a lot of joins and MongoDB just is not designed to be used like that. Furthermore you probably do not realize that every time you type populate
that is effectively another query to the server. I count 11 requests here.– Neil Lunn
Mar 24 at 9:13
1
1
Basically 11 requests to the server ( each
findBy
and every mention on populate
) just to return some data on a page is extremely excessive and will cause major performance problems for you ongoing. You really need to redesign this since you are still thinking far too much in relational terms. $lookup
can help by making that one request, but the "joins" are still a significant overhead here.– Neil Lunn
Mar 24 at 9:15
Basically 11 requests to the server ( each
findBy
and every mention on populate
) just to return some data on a page is extremely excessive and will cause major performance problems for you ongoing. You really need to redesign this since you are still thinking far too much in relational terms. $lookup
can help by making that one request, but the "joins" are still a significant overhead here.– Neil Lunn
Mar 24 at 9:15
add a comment |
1 Answer
1
active
oldest
votes
The mistake here is in this second populate
query:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
)
You are passing an object to populate function, and everytime you are using another populate inside that object, it overrides the old one, it is similar to any object definition.
Eg:
var a=
foo : "bar",
foo : "bar2",
foo : "bar3"
//the last foo overrides the first two
//a.foo = bar3
just like above example, last populate is overriding the previous populates.
Now back to solve your question,
You need to pass array to populate
field, so that it populates all the given fields you want
Try this:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: [
path: 'sitios', model: Sitio ,
path: 'turistas', model: Turista ,
path: 'categoria', model: CategoriaTour ,
path: 'empresa_turismo', model: EmpresaTurismo ,
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
]
)
replace the above code in place of your second populate query and it will work.
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%2f55322030%2fmake-many-populate-in-deep-populate-2nd-level%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The mistake here is in this second populate
query:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
)
You are passing an object to populate function, and everytime you are using another populate inside that object, it overrides the old one, it is similar to any object definition.
Eg:
var a=
foo : "bar",
foo : "bar2",
foo : "bar3"
//the last foo overrides the first two
//a.foo = bar3
just like above example, last populate is overriding the previous populates.
Now back to solve your question,
You need to pass array to populate
field, so that it populates all the given fields you want
Try this:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: [
path: 'sitios', model: Sitio ,
path: 'turistas', model: Turista ,
path: 'categoria', model: CategoriaTour ,
path: 'empresa_turismo', model: EmpresaTurismo ,
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
]
)
replace the above code in place of your second populate query and it will work.
add a comment |
The mistake here is in this second populate
query:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
)
You are passing an object to populate function, and everytime you are using another populate inside that object, it overrides the old one, it is similar to any object definition.
Eg:
var a=
foo : "bar",
foo : "bar2",
foo : "bar3"
//the last foo overrides the first two
//a.foo = bar3
just like above example, last populate is overriding the previous populates.
Now back to solve your question,
You need to pass array to populate
field, so that it populates all the given fields you want
Try this:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: [
path: 'sitios', model: Sitio ,
path: 'turistas', model: Turista ,
path: 'categoria', model: CategoriaTour ,
path: 'empresa_turismo', model: EmpresaTurismo ,
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
]
)
replace the above code in place of your second populate query and it will work.
add a comment |
The mistake here is in this second populate
query:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
)
You are passing an object to populate function, and everytime you are using another populate inside that object, it overrides the old one, it is similar to any object definition.
Eg:
var a=
foo : "bar",
foo : "bar2",
foo : "bar3"
//the last foo overrides the first two
//a.foo = bar3
just like above example, last populate is overriding the previous populates.
Now back to solve your question,
You need to pass array to populate
field, so that it populates all the given fields you want
Try this:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: [
path: 'sitios', model: Sitio ,
path: 'turistas', model: Turista ,
path: 'categoria', model: CategoriaTour ,
path: 'empresa_turismo', model: EmpresaTurismo ,
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
]
)
replace the above code in place of your second populate query and it will work.
The mistake here is in this second populate
query:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: path: 'sitios', model: Sitio ,
populate: path: 'turistas', model: Turista ,
populate: path: 'categoria', model: CategoriaTour ,
populate: path: 'empresa_turismo', model: EmpresaTurismo ,
populate:
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
)
You are passing an object to populate function, and everytime you are using another populate inside that object, it overrides the old one, it is similar to any object definition.
Eg:
var a=
foo : "bar",
foo : "bar2",
foo : "bar3"
//the last foo overrides the first two
//a.foo = bar3
just like above example, last populate is overriding the previous populates.
Now back to solve your question,
You need to pass array to populate
field, so that it populates all the given fields you want
Try this:
.populate(
path: 'tours_favoritos',
model: Tour,
populate: [
path: 'sitios', model: Sitio ,
path: 'turistas', model: Turista ,
path: 'categoria', model: CategoriaTour ,
path: 'empresa_turismo', model: EmpresaTurismo ,
path: 'guia', model: Guia,
populate: path: 'idiomas', model: Idioma
]
)
replace the above code in place of your second populate query and it will work.
answered Mar 27 at 15:41
Ravi Shankar BhartiRavi Shankar Bharti
4,34321439
4,34321439
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%2f55322030%2fmake-many-populate-in-deep-populate-2nd-level%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
1
The problem here is that without any knowledge of how the models actually interrelate and what the expected result would be we cannot determine what would be wrong with what you are doing. You would basically need to show sample data from each model that would be expected to be retrieved by all of the
populate()
calls. The real big problem here though is that's a lot of joins and MongoDB just is not designed to be used like that. Furthermore you probably do not realize that every time you typepopulate
that is effectively another query to the server. I count 11 requests here.– Neil Lunn
Mar 24 at 9:13
1
Basically 11 requests to the server ( each
findBy
and every mention onpopulate
) just to return some data on a page is extremely excessive and will cause major performance problems for you ongoing. You really need to redesign this since you are still thinking far too much in relational terms.$lookup
can help by making that one request, but the "joins" are still a significant overhead here.– Neil Lunn
Mar 24 at 9:15