Browse Source

search'

master
zeus 4 years ago
parent
commit
af7cea4478
  1. 93
      swarmlab-app/src/run/app.js

93
swarmlab-app/src/run/app.js

@ -359,6 +359,7 @@ cors(corsOptions), (req, res, next) => {
RES.start = req.query["start"] RES.start = req.query["start"]
RES.end = req.query["end"] RES.end = req.query["end"]
RES.swarmlabname = req.query["swarmlabname"] RES.swarmlabname = req.query["swarmlabname"]
RES.ok = 'ok'
/* /*
* *
* validate * validate
@ -389,26 +390,75 @@ cors(corsOptions), (req, res, next) => {
} else { } else {
const db = client.db('fluent'); const db = client.db('fluent');
//usersession.SOCKET.user = isvalid.user //usersession.SOCKET.user = isvalid.user
//usersession.SOCKET.scope = isvalid.scope // space delimeter console.log(JSON.stringify('mongo ----------------connected'))
//usersession.SOCKET.token = isvalid.token console.log('-----test------- '+JSON.stringify(RES))
//db.collection('log', onCollection); if ((typeof RES.start !== "undefined") && (typeof RES.end !== "undefined")) {
console.log(JSON.stringify('mongo connected')) if(DateTime.fromISO(RES.start).isValid){
var datestart = DateTime.fromISO(RES.start).toISODate() var datestart = DateTime.fromISO(RES.start)
var dateend = DateTime.fromISO(RES.end).toISODate() var dateend = DateTime.fromISO(RES.end)
var datestart = new Date(RES.start) var search_term = {
var dateend = new Date(RES.end) "$and": [
if(datestart && dateend){ {
var search_term = { $and: [ { date: { $gt: datestart } }, { date: { $lt: dateend } } ] }; "time": {
}else if(datestart){ $gte: datestart
var search_term = { $and: [ { date: { $gt: datestart } } ] }; }
}else if(dateend){ },
var search_term = { $and: [ { date: { $lt: dateend } } ] }; {
"time": {
$lt: dateend
}
},
]
}
}else{
RES.ok = 'no'
}
}else if(typeof RES.end !== "undefined"){
var dateend = DateTime.fromISO(RES.end)
if(DateTime.fromISO(RES.end).isValid){
var search_term = {
"$and": [
{
"time": {
$lt: dateend
}
}
]
}
}else{
RES.ok = 'no'
} }
}else if(typeof RES.start !== "undefined"){
var datestart = DateTime.fromISO(RES.start)
if(DateTime.fromISO(RES.start).isValid){
var search_term = {
"$and": [
{
"time": {
$gte: datestart
}
}
]
}
}else{
RES.ok = 'no'
}
}
if(RES.ok == 'ok'){
//var search_term = '{"$gte": new Date("2020-12-01T00:00:00.000Z") , "$lt": new Date("2020-12-11T16:17:36.470Z") }'
//var search_term = {"time" : {$lte : datenow}}
var resdataarray = [] var resdataarray = []
var resraw = {} var resraw = {}
var reslab = '' var reslab = ''
db.collection('logs').find(search_term, {}).toArray() var datestart1 = DateTime.fromISO(RES.start)
console.log('-----now1------- '+JSON.stringify(search_term))
console.log('-----now2------- '+JSON.stringify(datestart1))
console.log('-----now3------- '+JSON.stringify(datestart))
db.collection('logs').find(search_term).toArray()
//db.collection('logs').find({"time" : {$gt : datestart}}).toArray()
.then(item => { .then(item => {
console.log('item '+JSON.stringify(item))
for (let i in item) { for (let i in item) {
reslab = item[i].tailed_path reslab = item[i].tailed_path
var segment_array = reslab.split( '/' ); var segment_array = reslab.split( '/' );
@ -436,16 +486,17 @@ cors(corsOptions), (req, res, next) => {
RES.error_msg = err RES.error_msg = err
res.json(RES) res.json(RES)
}) })
} else{ // RES.ok
RES.error_msg = 'no date'
res.json(RES)
} }
}); } // error mongo connect
}else{ }); // mongo connect
}else{ // token error
RES.data = 'no' RES.data = 'no'
RES.error_msg = "token err" RES.error_msg = "token err"
res.json(RES) res.json(RES)
}
}
})() })()
}); });

Loading…
Cancel
Save