These are chat archives for Automattic/mongoose

24th
Jan 2019
Marko Bolliger
@cannap
Jan 24 14:52

hi i have a question when i use

const user = await User.aggregate([
      { $match: { privateLink } },

      {
        $project: {
          privateLink: {
            $cond: [{ $eq: ['$firstName', '-'] }, false, '$privateLink']
          }
        }
      }
    ])

how can i include all other fields and keep the condition?

without writing each field
Marko Bolliger
@cannap
Jan 24 14:57
nvm got it shoudl read more mongoose docs
i mean the mongodb
danielmercy
@danielmercy
Jan 24 18:23
Hi there
I am having some issues populating my model data in mongodb with mongoose. Pls i'd be glad if you could help.
danielmercy
@danielmercy
Jan 24 18:29
export const SchoolRes = {
    schools: async (_: any) => {
        **const schools: any = await School.find().populate({path: 'faculties', populate: {path: 'courses'}}).populate('tuitions')**
        return schools.map((school: ISchool): any => {
            console.log(school.faculties);
            let faculties_ = school.faculties.map(faculty => {
                let courses_ = faculty.courses.map(course => {
                    return course.toGraph();
                });
                return faculty.toGraph();
            });

            let tuitions_ = school.tuitions.map(tuition => { 
                return { label: tuition.label, price: tuition.price, school: tuition.school.toString(), _id: tuition._id.toString(), createdAt: tuition.createdAt, updatedAt: tuition.updatedAt }
            });
            return { 
                ...school._doc,
                _id: school.id, 
                established: school._doc.established_year,
                faculties: faculties_,
                tuitions: tuitions_
            };
        });
    },