I have the following schema's:
var Child = new mongoose.Schema({
'field': String,
'value': String
});
var Parent = new mongoose.Schema({
'name': String,
'children': [ Child ]
});I want to return the Parent for which one of the Child's corresponds to the following JSON object:
{ 'field': 'Family Name', 'value': 'Smith' }I have tried this:
Parent.findOne({ 'children': { 'field': 'Family Name', 'value': 'Smith' } }, fn ...)but it keeps on retrieving null.
My environment is: Node.js, Mongoose, MongoDB
Parent.findOne({ 'children': { $elemMatch: { 'field': 'Family Name', 'value': 'Smith' } } }, fn ...)