0

I am trying to find a specific object in my mongodb, currently I iterate through the entire id and match string by string in jade template engine, but surely there is a more efficient way of doing search object in mongo

app.put('/tasks/:id', function(req, res){
  Task.findById(req.params.id, function (err, doc){
    doc.updated_at = new Date();
    doc.task = req.body.task.task;
    doc.save(function(err) {
      if (!err){
        res.redirect('/tasks');
      }
      else {
        // error handling
      }
    });
  });
});

Alternatively, I can

db.TASK.find(
   { Task: 'blah blah.....' },
)

in the command line

but I don't know how to have the server side respond to different task dynamically, that is 'blah blah' should be dynamic and I don't know how to incorporate that into node.js

Any hint would be appreciated

user2654176
  • 115
  • 7
  • By the way, you probably shouldn't pull the entire document up just to set/update some fields. See update() and $set. – Josh C. Sep 04 '13 at 22:07
  • Is the { Task: 'blah blah.....' } object the criteria you want to match on? – Josh C. Sep 04 '13 at 22:09
  • {Task:'adding'} would be in the case of what I am tring to do, it will just be some strings that I am searching through the database for – user2654176 Sep 04 '13 at 22:14
  • Possible duplicate? http://stackoverflow.com/questions/10929443/nodejs-mongodb-getting-data-from-collection-with-findone You may want to use mongoskin or node-mongodb-native packages – Dominic Tancredi Sep 04 '13 at 22:50
  • Disregard my comment. I didn't realize you were using mongoose. – Dominic Tancredi Sep 04 '13 at 22:58

0 Answers0