Two arrays inside an array with mongodb/mongoose

Viewed 56

I have the following mongodb's query:

db.history.distinct('city',{code: 'A-200-01'})

Then I get this:

[1.0, 2.0]

As you can see it's a simple array. And i'd like to get an array with two arrays inside of it using a mongoose or mongodb's query. Something like this:

"property": [ [1.0], [2.0] ]

This is my first time using mongoose and mongodb's queries so i hope you guys could help me, that would be awesome

1 Answers

No need to use mongodb or mongoose for that (it is probably impossible). If you need to modify output to different format the node.js itself is most usable tool.

const original = [1.0, 2.0]
const arr = [];
original.forEach(item => arr.push([item]));
console.log({property: arr});

Related