0

I have 2 functions which uses mongojs to connect. Both will use 2 different collections with different schemas but with same name "users". Here is the code :

var findAll = function(req, res) {
var users = db.collection('users'); //this initializes db collection
db.users.find({},function(err,users){
   if(err){
       res.json(err);
   } else{
       res.json(users);
        users = null;
   }
});
};
var getbyUserName = function(req,res) {
var username = req.params.username;    
db.users.find({'username':username},function(err,result){
    if(err){
        res.send(err);
    }else{
        res.json(result);
    }
});

};

I am not initializing "users" collection in function getbyUsername but, it is using "users" collection initialized in first function. Is there any way I can clear the collections after function 1 is successfully executed ?

Alberto De Caro
  • 5,147
  • 9
  • 47
  • 73
codejammer
  • 469
  • 1
  • 7
  • 18

1 Answers1

0

maybe db.collection('users').drop(); ? See if you can find something in http://mongodb.github.io/node-mongodb-native/markdown-docs/collections.html that helps

Sascha Kaestle
  • 1,293
  • 12
  • 15
  • `db.collection('users').drop()` will drop the entire collection. I want to disable access to that collection 'users' once the execution of first function is finished – codejammer Apr 08 '13 at 10:31