0

Hi I am new with javascript, there is a problem that is driving me crazy: what is the difference between an object staticly declared as this one :

{$or:[{tc_clpar_id:4,tc_par_id:{$in:[79,80]}},{tc_clpar_id:5,tc_par_id:{$in:[105,106]}}]}

and an object costruct at run-time, with this function:

function buildQuery(self,setting,query){
var query = {$or:[]};
cl = 'tc_cl'+self.family+'_id';
att ='tc_'+self.family+'_id';
keys = Object.keys(setting);
for( var k=0;k<keys.length;k++){
    ch = keys[k];
    var q = {};
    q[cl] = ch;
    q[att] = {$in:setting[ch]};
    query.$or.push(q);
}
return query;

this object is used as query for the node-mongodb-native driver, the first one works, the object return by the function in correct, I checked the two object with assert.deepEqual, there are no errors, but using the produced object I get an empty resultset, I do not have any clue about the problem, I thought maybe something strange with the scope as the function is a method of another object, or maybe with the garbage collector.

arpho
  • 1,576
  • 10
  • 37
  • 57
  • 2
    For arguments sake, could you share the output of a call to `buildQuery`? – pdoherty926 Sep 13 '13 at 04:20
  • for this input {5:[105,106],4:[79,80]} I get this output from buildQuery: { '$or': [ { tc_clpar_id: '4', tc_par_id: [Object] }, { tc_clpar_id: '5', tc_par_id: [Object] } ] } that is equal to this: {$or:[{tc_clpar_id:4,tc_par_id:{$in:[79,80]}},{tc_clpar_id:5,tc_par_id:{$in:[105,106]}}]} at least with assert.deepEqual(expected,output) they result equal – arpho Sep 13 '13 at 13:55

0 Answers0