mean stack - How to Query Subdocuments of 1 Schema that match the contains of another Model Subdocument Schema -


i writing mean stack application defines 2 (2) models.

var job = db.model('job', {     ...     kind: {         baby: false,         pet: false,         house: false,     } });  var person = db.model('person', {     ...     kind: {         baby: false,         pet: false,         house: false,     } }); 

i create kind field sub-document since getting stored in field input of type checkbox in angularjs app.

my question relates query of job person has same kind equal true.

for example, if person has checked baby , pet in profile query jobs have baby , pet true.

is way store checkbox inputs html form in mongodb? if so, query string achieve results. if not, correct way store checkbox inputs in mongodb?

i dont know amount of data involved in people , jobs collections neither purpose of query/main objective of app. based on that, here thoughts:

  • have angular service data people , jobs collections , store app loads. everytime checkbox checked/unchecked use ng-change , custom angular filters on service data achieve want, instead of querying database;
  • if want/need query database everytime checkboxes checked/unchecked can send request server checkboxes values (something {baby: false, pet: false, house: false} in req.body). once request received query usual , return matching documents:

    var job = mongoose.model('job'); job.find({kind: req.body}, function (err, docs) {     if(err) {         // handle err     }     res.json(docs); }); 

hope helps can't more specific.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -