server/mongodb_rest.js
function(req, res, fromMessage) {
            var name = req.params.name;
            var id   = this.toId(req.params.id);
            if (typeof id === 'undefined' || id === '') {
                return res.send(400, "invalid id.");
            }
            var doc   = {};
            doc._id   = id;
            doc._time = new Date().getTime();
            var collection = new mongodb.Collection(this.db, name);
            if (id === 'all' || id === 'clean') {
                collection.drop(function (err) {
                    if(err) {
                        res.send(400, err);
                    } else {
                        var msg = {
                            method: 'delete',
                            id: doc._id,
                            time: doc._time
                        };
                        rest.onSuccess(name, msg, fromMessage);
                        res.send(doc);
                    }
                });
            } else {
                collection.remove({ "_id" : id }, { }, function(err, n){
                        if(err) {
                            res.send(400, err);
                        } else {
                            if (n==0) {
                                res.send(404, 'Document not found!');
                            }
                            if (n > 0) {
                                var msg = {
                                    method: 'delete',
                                    id: doc._id,
                                    time: doc._time,
                                    data: doc
                                };
                                rest.onSuccess(name, msg, fromMessage);
                                res.send(doc);
                            }
                        }
                    }
                );
            }
        }
function(req, res, fromMessage) {
            var name = req.params.name;
            var id   = this.toId(req.params.id);
            if (typeof id === 'undefined' || id === '') {
                return res.send(400, "invalid id.");
            }
            var doc   = {};
            doc._id   = id;
            doc._time = new Date().getTime();
            var collection = new mongodb.Collection(this.db, name);
            if (id === 'all' || id === 'clean') {
                collection.drop(function (err) {
                    if(err) {
                        res.send(400, err);
                    } else {
                        var msg = {
                            method: 'delete',
                            id: doc._id,
                            time: doc._time
                        };
                        rest.onSuccess(name, msg, fromMessage);
                        res.send(doc);
                    }
                });
            } else {
                collection.remove({ "_id" : id }, { }, function(err, n){
                        if(err) {
                            res.send(400, err);
                        } else {
                            if (n==0) {
                                res.send(404, 'Document not found!');
                            }
                            if (n > 0) {
                                var msg = {
                                    method: 'delete',
                                    id: doc._id,
                                    time: doc._time,
                                    data: doc
                                };
                                rest.onSuccess(name, msg, fromMessage);
                                res.send(doc);
                            }
                        }
                    }
                );
            }
        }
function ( req , res , fromMessage ) { var name = req . params . name ; var id = this . toId ( req . params . id ) ; if ( typeof id === 'undefined' || id === '' ) { return res . send ( 400 , "invalid id." ) ; } var doc = { } ; doc . _id = id ; doc . _time = new Date ( ) . getTime ( ) ; var collection = new mongodb . Collection ( this . db , name ) ; if ( id === 'all' || id === 'clean' ) { collection . drop ( function ( err ) { if ( err ) { res . send ( 400 , err ) ; } else { var msg = { method : 'delete' , id : doc . _id , time : doc . _time } ; rest . onSuccess ( name , msg , fromMessage ) ; res . send ( doc ) ; } } ) ; } else { collection . remove ( { "_id" : id } , { } , function ( err , n ) { if ( err ) { res . send ( 400 , err ) ; } else { if ( n == 0 ) { res . send ( 404 , 'Document not found!' ) ; } if ( n > 0 ) { var msg = { method : 'delete' , id : doc . _id , time : doc . _time , data : doc } ; rest . onSuccess ( name , msg , fromMessage ) ; res . send ( doc ) ; } } } ) ; } }
Delete a contact
Delete a contact