ozomer / node-red-contrib-mongodb2

MongoDB driver node for Node-RED
Apache License 2.0
15 stars 19 forks source link

variable in payload message #42

Closed accateo closed 5 years ago

accateo commented 5 years ago

Hi, after different hours of research, I found how to make a find.toArray with projection:

msg.payload = [{timestamp: {$gt: date_from.getTime() , $lt: date_to.getTime() }},{"fields": { "name": 1,timestamp:1}}]

Now the problem is, if I want to substitute "name" with a variable? How can I do? I tried:

msg.payload = [{timestamp: {$gt: date_from.getTime() , $lt: date_to.getTime() }},{"fields": { var: 1,timestamp:1}}]

but it doesn't work. Any idea?

Thanks

accateo commented 5 years ago

Solution in ES6:

msg.payload = [{timestamp: {$gt: date_from.getTime() , $lt: date_to.getTime() }},{"fields": { [var]: 1,timestamp:1}}]