Skip to content

Instantly share code, notes, and snippets.

@DouglasHennrich
Created February 20, 2015 20:03
Show Gist options
  • Save DouglasHennrich/88dd1a73518ed968edfa to your computer and use it in GitHub Desktop.
Save DouglasHennrich/88dd1a73518ed968edfa to your computer and use it in GitHub Desktop.
var query = { $and : [
{ idFace : { $in : [req.body.idFace] } }
, { "users.gender" : 'male' }
]}
;
Model.find( query )
.populate({
path : 'users.user'
, match : { gender : 'male' }
})
.exec( function( err, data ){
if (err){ console.log( 'Erro: ' + err ); return res.json(err); }
console.log( 'Sucesso: ', data );
res.json( data );
});
(function(){
'use_strict'
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var UserSchema = new Schema({
_id : false
, user : { type : Schema.Types.ObjectId, ref: 'User' }
, gender : { type : String, default : '' }
});
var EventoSchema = new Schema({
idFace : { type : String, default : '' }
, name : { type : String, default : '' }
, matchs : [{ type : Schema.Types.Mixed }]
, likes : [{ type : Schema.Types.Mixed }]
, users : [UserSchema]
});
module.exports = mongoose.model( 'Evento', EventoSchema );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment