Reputation: 13
I am using createIndex()
in MongoDB in Node.js. I was wondering how I could insert a variable into createIndex
.
For instance I have var x = "insert"
. I would like to make an index called "insert" by using x
. I have tried createIndex({x:1})
but all this does is make x
the index.
Upvotes: 1
Views: 183
Reputation: 801
In es6
createIndex({[x]:1})
In es5
var indexQuery = {};
indexQuery[x] = 1;
createIndex(indexQuery);
Upvotes: 1