Skip to content

Instantly share code, notes, and snippets.

@DouglasHennrich
Created February 1, 2015 15:50
Show Gist options
  • Save DouglasHennrich/84673a8804fce2315d46 to your computer and use it in GitHub Desktop.
Save DouglasHennrich/84673a8804fce2315d46 to your computer and use it in GitHub Desktop.
Quero adicionar os dois IDs( req.body.meuId e req.body.outroId ) dentro do array matchs dentro do field "campo"
update_match = function(req,res){
var query = { _id : req.params.id }
, mod = { $pushAll : { 'matchs.campo' : [mongoose.Types.ObjectId( req.body.meuId ),
mongoose.Types.ObjectId( req.body.outroId )] } }
;
Model.update( query, mod, function(err,data){
if (err){ console.log( err ); return res.json(err); }
console.log( 'Sucesso: ' + data );
res.json( data );
})
};
{
"_id": ObjectId("54ce4a92dba7d25e10a30cd0"),
"users": [
ObjectId("54cd3f34a5e4e1c4d181fcd5"),
ObjectId("54ce4aa1dba7d25e10a30cd1")
],
"matchs": [ ],
"name": "Nome do Evento",
"idFace": "456875432",
"__v": 0
}
(function(){
'use_strick'
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var EventoSchema = new Schema({
idFace : { type : String, default : '' }
, name : { type : String, default : '' }
, matchs : [{ type : Schema.Types.ObjectId, ref : 'User' }]
, users : [{ type : Schema.Types.ObjectId, ref: 'User' }]
});
module.exports = mongoose.model( 'Evento', EventoSchema );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment