Calling different collections

Hello all,

I have got mydbs.js and I have got 3 collections in it.

I can call like as below my collections:

  var xrec = Dbs.MyXDb1.find({},{sort:{recdate:-1},limit:1000}).fetch();
  if (xrec){
    console.log(xrec);
  }

But I would like to call like as below:

  tempdb = "MyXDb1";
  xrec = Dbs.tempdb.find({},{sort:{recdate:-1},limit:1000}).fetch();
  if (xrec){
    console.log(xrec);
  }

  tempdb = "MyXDb2";
  xrec = Dbs.tempdb.find({},{sort:{recdate:-1},limit:1000}).fetch();
  if (xrec){
    console.log(xrec);
  }

Is it possible? Or what should I do for this problem.

Thanks in advance.

Dbs[tempdb].find

Check about JavaScript objects and keys

1 Like