I'm new to nodejs and there's a problem I can not solve. I use nodejs and firebase database. In the database I have a collection that I have on "engineers", and I want move the data from the database to the array.
This is the database I have: I want to turn preferences into an array:
I want to get this array:
const engineers = [
// frontend engineers
{ html: 5, angular: 5, react: 3, css: 3 },
{ html: 4, react: 5, css: 4 },
{ html: 4, react: 5, vue: 4, css: 5 },
{ html: 3, angular: 3, react: 4, vue: 2, css: 3 },
// backend engineers
{ nodejs: 5, python: 3, mongo: 5, mysql: 4, redis: 3 },
{ java: 5, php: 4, ruby: 5, mongo: 3, mysql: 5 },
{ python: 5, php: 4, ruby: 3, mongo: 5, mysql: 4, oracle: 4 },
{ java: 5, csharp: 3, oracle: 5, mysql: 5, mongo: 4 },
// mobile engineers
{ objc: 3, swift: 5, xcode: 5, crashlytics: 3, firebase: 5, reactnative: 4 },
{ java: 4, swift: 5, androidstudio: 4 },
{ objc: 5, java: 4, swift: 3, androidstudio: 4, xcode: 4, firebase: 4 },
{ objc: 3, java: 5, swift: 3, xcode: 4, apteligent: 4 },
// devops
{ docker: 5, kubernetes: 4, aws: 4, ansible: 3, linux: 4 },
{ docker: 4, marathon: 4, aws: 4, jenkins: 5 },
{ docker: 3, marathon: 4, heroku: 4, bamboo: 4, jenkins: 4, nagios: 3 },
{ marathon: 4, heroku: 4, bamboo: 4, jenkins: 4, linux: 3, puppet: 4, nagios: 5 }
];
This is the code I wrote down so far, but it does not work for me.
//enginer.js file
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.getPreferancesArray = (req,res) => {
let engineers = {};
db.collection(`/preferences`).get().then((doc) => {
if (doc.exists) {
engineers = doc.data();
console.log(engineers);
}
res.json(engineers);
});
};
//index.js
const {
getPreferancesArray
} = require('./enginer');
const cors = require('cors');
app.use(cors());
app.get('/kmeansArray', FBAuth, getPreferancesArray);
exports.api = functions.region('europe-west1').https.onRequest(app);
The problem is: I can not turn content from the database into an array, I do not understand what the problem I have been delaying it for several hours. I want the enginer variable to have the array
