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!
