Home > database >  Two arrays inside an array with mongodb/mongoose
Two arrays inside an array with mongodb/mongoose

Time:07-30

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

CodePudding user response:

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