خرید بک لینک

Vote count: 0

Hi I am using Express to work with MongoDB. I am pretty new to both. I got a find function working, it looks like this:

function find (current_collection, cb) {
  getCollection(current_collection, function (err, collection) {
    collection.findOne({
      'identity.sender.id': '1234abcd'
    }, function (err, result) {
      // ... some err and cb handling
    });
  });
}

I logged the result and everything looks fine. I want to this code somewhere else, so I tried to use variables in the query and turned the function into something like this:

function find (current_collection, val, cb) {
  getCollection(current_collection, function (err, collection) {
    collection.findOne({
      'identity.sender.id': val
    }, function (err, result) {
      // ... some err and cb handling
    });
  });
}

// I then called the function on a separate file, like this and it worked

function get_user_data (){
    var x = getModel().find('users', '1234abcd', function(err, result){
    //
    });
    return x;
}

However, when i tried to go one step further but using variable for the query attribute, everything stopped working and i got error:

function find (current_collection, attr, val, cb) {
  getCollection(current_collection, function (err, collection) {
    collection.findOne({
      attr : val
    }, function (err, result) {
      // ... some err and cb handling
    });
  });
}

// I then called the function on a separate file, this time, did not work!!

function get_user_data (){
    var x = getModel().find('users','identity.sender.id', '1234abcd', function(err, result){
    //
    });
    return x;
}

Really not sure what I have done incorrectly. Please help!! Thanks in advance!

asked 1 min ago

برچسب: using variables in sql,using variables in sed,using variables in bash,using variables in excel,using variables in batch files,using variables in powershell,using variables in html,using variables in css,using variables in mysql,using variables in oracle sql, نویسنده: استخدام کار تاريخ: پنجشنبه 4 شهريور 1395 ساعت: 3:48

صفحه بندی