File tree Expand file tree Collapse file tree
backend/src/utils/decoders Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const mongoose = require ( 'mongoose' ) ;
2- const config = require ( '../../../config' ) ;
32
4- const MONGO_URI = config . mongoSourceConnector ; // cambia "mydb" con il tuo database
5-
6- // Oggetto che conterrà il modello una volta creato
7- let Datapoint ;
8-
9- mongoose . connect ( MONGO_URI , {
10- useNewUrlParser : true ,
11- useUnifiedTopology : true
12- } )
13- . then ( ( ) => {
14- console . log ( "Connesso a MongoDB!" ) ;
15-
16- // definizione schema
17- const datapointSchema = new mongoose . Schema ( {
18- source : String ,
19- survey : String ,
20- surveyName : String ,
21- region : String ,
22- fromUrl : String ,
23- timestamp : String ,
24- dimensions : Object ,
25- value : Number
26- } , { strict : false } ) ;
27-
28- // creazione modello
29- Datapoint = mongoose . model ( 'Datapoint' , datapointSchema ) ;
30-
31- } )
32- . catch ( err => {
33- console . error ( "Errore di connessione a MongoDB:" , err ) ;
34- } ) ;
35-
36- // esportiamo una funzione che ritorna il modello solo quando è pronto
37- module . exports . getDatapointModel = async function ( ) {
38- // aspetta che la connessione sia pronta
39- if ( ! Datapoint ) {
40- await mongoose . connection . asPromise ( ) ; // Node 18+ / mongoose 7+
41- }
42- return Datapoint ;
43- } ;
3+ const datapointSchema = new mongoose . Schema ( {
4+ source : String ,
5+ survey : String ,
6+ surveyName : String ,
7+ region : String ,
8+ fromUrl : String ,
9+ timestamp : String ,
10+ dimensions : Object ,
11+ value : Number
12+ } , { strict : false } ) ;
13+
14+ module . exports = mongoose . model ( 'Datapoint' , datapointSchema ) ;
You can’t perform that action at this time.
0 commit comments