Answer the question
In order to leave comments, you need to log in
Mongoose: count to linked collections
Good day to all!
I am learning Node.JS, for the first project I chose the Express + Mongoose bundle, and I have already encountered a number of problems.
There are 2 models:
var Institution = new mongoose.Schema({
name: {
type: String,
required: [true, 'Поле "Название заведения" не может быть пустым']
}
});
module.exports = mongoose.model('institution', Institution);
var Faculty = new mongoose.Schema({
institution: {
type: mongoose.Schema.ObjectId,
ref: 'institution'
},
name: {
type: String,
required: [true, 'Поле "Название факультета" не может быть пустым']
}
});
module.exports = mongoose.model('faculty', Faculty);
Faculty.find({institution: institution._id}, function(err, faculties) {
// ...
});
Answer the question
In order to leave comments, you need to log in
Do you need faculties separate from institutes?
If not, then shove the faculties inside the institutes. Then, when selecting institutes, you will immediately have an array of faculties.
In case the collections are different, there are no options other than as you described.
With the __facultiesCount field, a normal solution. Make a separate method for recalculating quantities and do not delete by hand.
Try populate, instead of IDs of institutions in the faculty, it will substitute the objects of institutions from another table
Faculty.find({institution: institution._id}).populate('institution').exec( function(err, faculties) {
// ...
} );
Hello. Take books on mathematics and algorithms - and go ahead to solve / read / program. And all these beautiful words "I would like to work in the field related to artificial intelligence" are just words. You don't even understand what's behind them. Plus a guarantee that tomorrow you will like iron, the day after tomorrow - 3D graphics, and watch "Terminator" - you want to plunge into robotics. That is, your desires are like the wind at that age - I would not pay attention to them. I am sure, because if you understood what it is to work with AI, you would have long known where to go.
> difficult choice of higher education institution
Need learning words conjugation in a sentence.
IP is programming with deep use of a mat. Apparatus
Accordingly, either to the faculty of programming or to the mat. faculty.
All graduates have a common misconception: "Now let's go to college and they will teach us there!"
In institutes they are not engaged in training, in institutes they are engaged in teaching the subject.
The quality of teaching is also very lame, because the theory of several books is spread over several years. If we take programming, then many teachers themselves have never written anything more or less complicated in their lives, but operate only with theoretical knowledge. That is, there is no real experience, so there is nothing to share.
Your knowledge and skills are only in your hands:
Take any programming language and books on mathematics and go.
Write, write and write programs again, theory without practice is nothing.
+ There is a nuance that will definitely contribute to the education process:
Drinking will begin from the second year - partying, girls, first job, etc.)
There is a specialty "Specialty 220100 Computers, complexes, systems and networks".
It's somewhere between programming and electronics. We were taught to develop computer architecture and software for it. Some basic knowledge about FPGAs. I think it's not the best thing for an AI programmer to be a pure programmer. Because to solve AI problems, a new architecture, which does not yet exist, or an FPGA may be required. At the same time, we had both discrete and computational mathematics in full.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question