Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array declaration using a variable

I've this:

var tmp = "Test";

and want that:

Books.update({_id: data._id},{$set:{tmp: [0,0,0,0,0]}});

Now I get an array like this: tmp: [0,0,0,0,0] But I want that: Test [0,0,0,0,0]

Have somebody an idea how I can do that?

like image 806
Struct Avatar asked Aug 27 '26 09:08

Struct


1 Answers

var tmp = "Test",
    set = {};

set[tmp] = [0,0,0,0,0];
Books.update({_id: data._id},{$set: set});
like image 99
Trevor Dixon Avatar answered Aug 28 '26 23:08

Trevor Dixon