Here is my schema
var mongoose = require('mongoose');
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var schema = new mongoose.Schema({
month:String,
year:String,
endDate:Date,
bio:[{
_id:false,
id:String,
date:Date,
inTime:Date,
outTime:Date,
workingHours:String
}],
createdBy:ObjectId
},{timestamps:true});
schema.index({month: 1, year: 1 }, { unique: true });
module.exports=mongoose.model('bioMatrix',schema);
i want to get only bio data whose id is say "18" I am trying like
BioMatrix.find({month:11,year:2016,'bio.id':"18"},{bio:1,_id:0})
.exec(function(e,b){
console.log(JSON.stringify(b[0]))
})
But it show all the bio data wich is around 1000
How to find only filter array
also tried
BioMatrix.find( { bio : { $elemMatch: { id : "18" } } })
.exec(function(e,b){
console.log(e)
console.log(JSON.stringify(b))
})