viele Anpassungen

This commit is contained in:
2023-11-07 08:05:54 +00:00
parent 91e55f58bf
commit 70f928d961
12 changed files with 134 additions and 74 deletions
+9 -9
View File
@@ -14,23 +14,23 @@ let MONGOUSRP = process.env.MONGOUSRP;
let MONGOBASE = process.env.MONGOBASE;
if (MONGOHOST === undefined) { MONGOHOST = 'localhost';}
if (MONGOPORT === undefined) { MONGOPORT = 27097; }
if (MONGOPORT === undefined) { MONGOPORT = 27017; }
if (MONGOAUTH === undefined) { MONGOAUTH = 'false'; }
if (MONGOBASE === undefined) { MONGOBASE = 'allsensors'; }
if (MONGOBASE === undefined) { MONGOBASE = 'sensor_data'; }
let MONGO_URL = 'mongodb://'+MONGOHOST+':'+MONGOPORT; // URL to mongo database
if (MONGOAUTH === 'true') {
MONGO_URL = 'mongodb://'+MONGOUSRP+'@' + MONGOHOST + ':' + MONGOPORT + '/?authSource=' + MONGOBASE; // URL to mongo database
// MONGO_URL = 'mongodb://'+MONGOUSRP+'@' + MONGOHOST + ':' + MONGOPORT + '/?authSource=' + MONGOBASE; // URL to mongo database
MONGO_URL = 'mongodb://'+MONGOUSRP+'@' + MONGOHOST + ':' + MONGOPORT + '/?authSource=admin'; // URL to mongo database
}
export const properties_collection = 'pptest'
export const properties_collection = 'properties'
export const connectMongo = async () => {
try {
// logit(`Try to connect to ${MONGO_URL}`)
// let client = await MongoClient.connect(MONGO_URL, { useNewUrlParser: true , useUnifiedTopology: true })
let client = await MongoClient.connect(MONGO_URL)
logit(`Mongodbase connected to ${MONGO_URL}`)
// logit(`Mongodbase connected to ${MONGO_URL}`)
return client
}
catch(error){
@@ -104,7 +104,7 @@ export const getOneproperty = async (sid) => {
let ret = {error: false}
let client = await connectMongo()
try {
ret.properties = await client.db(MONGOBASE).collection("properties_collection")
ret.properties = await client.db(MONGOBASE).collection(properties_collection)
.findOne({_id: sid})
} catch (e) {
ret = {error: true, errortext: e}
@@ -154,7 +154,7 @@ export const fetchActData = async (opts) => {
let options = { projection: {_id: 0, values: 1, datetime: 1}, sort: {datetime: 1}}
let client = await connectMongo()
try {
ret.values = await client.db(MONGOBASE).collection('sensors')
ret.values = await client.db(MONGOBASE).collection('noise_sensors')
.find(query, options).toArray()
}
catch(e) {
@@ -271,7 +271,7 @@ export const fetchNoiseAVGData = async (opts) => {
let grpId = {$dateToString: {format: '%Y-%m-%dT%H:00:00Z', date: '$datetime'}}
let client = await connectMongo()
try {
docs = await client.db(MONGOBASE).collection('sensors').aggregate([
docs = await client.db(MONGOBASE).collection('noise_sensors').aggregate([
{$sort: sorting}, // sort by date
{$match: datRange}, // select only values in give data range
{