0

I have the following schema :

const ClientManagerSchema = new Schema({
    name : { type : String,  required : true},
    project : [ProjectSchema]
});

The project one looks like this :

const ProjectSchema = new Schema({
    companyName : {type: String , required : true}, 
    projectName : String, 
    projectManager : String, 
    projectManagerUrl : String, 
    employees : [], 
    contactPerson : [], 
    employeeInfo : [], 
    projectHours : [], 
    trelloUrl : String, 
    dataStudioUrl : String,
    projectUrl : String,
    AnalyticsEmail : String,
    companyId : String,
    projectId : String,
    total : Number,
    totalIn : Number,
    totalSt : Number,
    totalSale : Number,
    earliestDate : String, 
    firstEvaluation : String,
    secondEvaluation : String, 
    firstEvaluationIndex : Number,
    secondEvaluationIndex : Number,
    revenueGroups : [RevenueGroupSchema],
    revenueGroupsIn : [RevenueGroupSchema],
    revenueGroupsSt : [RevenueGroupSchema],
    sales : [RevenueGroupSchema],
    saleData : [],
});

I want to select all documents from my database that have the company name "test bv". But since the projects value is nested im not sure how to do it. I could also lift the value to a level where i can easily access it but thats not optimal.

I tried some things which didn't work :

ClientManager.find({'companyName': 'test bv'}).then((res) => console.log(res)).catch(err => console.log(err))

This gave me an empty array..

2 Answers 2

2

change this find({'companyName': 'test bv'})to this find({'project.companyName': 'test bv'})

Sign up to request clarification or add additional context in comments.

Comments

1
ClientManager.find({'project.companyName': 'test bv'}).then((res) => console.log(res)).catch(err => console.log(err))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.