0

from the id I recovers in a collection of documents :

exports.dropWithDocumentId = function(req,res) {
    Flux.loadByDocumentId(req.params.id,function(err,flux){
        if (err) { res.sendStatus(500); return; }


        console.log(flux) ;
        res.json(flux);
    });
}

and it gives me the following result:

[ { _id: 55a37838363ea5c00913cb4b,
    texte: 'testtt',
    nomUtilisateur: 'user1',
    formation: 5587d9b96c861a800f6d6563,
    diplome: 5587e7acb90c3e581a0393ac,
    __v: 2,
    tags: [],
    documents:
     [ { document: 55a37824363ea5c00913cb4a,
         modele: 'Fichier',
         _id: 55a37838363ea5c00913cb4c } ],
    type: 1,
    commentaires:
     [ { _id: 55a3790ff6c0f588056b5b82,
         user: 5587e7acb90c3e581a0393ac,
         prest: 5587d9b96c861a800f6d6563,
         texte: 'aaaaaaaaaaaa',
         date: Mon Jul 13 2015 10:38:39 GMT+0200 (Paris, Madrid (heure d'été))
,
       { _id: 55a37906f6c0f588056b5b80,
         user: 5587e7acb90c3e581a0393ac,
         prest: 5587d9b96c861a800f6d6563,
         texte: 'aqqqqqq',
         date: Mon Jul 13 2015 10:38:30 GMT+0200 (Paris, Madrid (heure d'été))
 ],
    date: Mon Jul 13 2015 10:35:04 GMT+0200 (Paris, Madrid (heure d'été)) } ]

Now I want to delete all the documents in this collection from the id :

exports.dropWithDocumentId = function(req,res) {
    Flux.loadByDocumentId(req.params.id,function(err,flux){
        if (err) { res.sendStatus(500); return; }

        flux.forEach( function (doc) {

            doc.remove();
          });
        //console.log(flux.type) ;
        res.json(flux);
    });
}

but it does not work !! help me

Cheps
  • 465
  • 2
  • 7
  • 16
  • 1
    You are using an "instance". Do `Flux.remove({},function(err,result) { "_id": req.params.id })` instead and use the "Model". You also do not need to `.find()` it first. – Blakes Seven Jul 13 '15 at 09:21
  • possible duplicate of [How do I remove documents using Node.js Mongoose?](http://stackoverflow.com/questions/5809788/how-do-i-remove-documents-using-node-js-mongoose) – Blakes Seven Jul 13 '15 at 09:22
  • sorry but does not work , – Cheps Jul 13 '15 at 09:43
  • 2
    Yes it does. You need to read the "duplicate question" ( which means you are not the first to do exactly the same ) and follow the example there. And what I also said above. – Blakes Seven Jul 13 '15 at 09:45

0 Answers0