142 lines
4.2 KiB
JavaScript
142 lines
4.2 KiB
JavaScript
var jobId = 62;
|
|
// db.applications.find({ "jobId": jobId })
|
|
var appIds = db.applications.find({ "jobId": jobId }, { "_id": 1 }).map(item => item._id);
|
|
// print (appIds)
|
|
// db.application_details.remove({'appId':{'$in': apps}},function(){ });
|
|
// db.applications.remove({ "jobId": jobId });
|
|
db.appfiles.find({ appId: {$in: appIds}});
|
|
var fileIds = db.appfiles.find({ appId: {$in: appIds}}, { _id: 1}).map(it => it._id);
|
|
// print (fileIds);
|
|
// db.appfiles.remove({ appId: {$in: appIds}});
|
|
|
|
// Filter spray data by fileIds
|
|
// var fileIds = [ObjectId("5b27bc30c3f755062ee1ad10"), ObjectId("5b27bc30c3f755062ee1ad0a")];
|
|
// db.application_details.find({ fileId: {$in: fileIds}}, {_id: 0, gpsTime:1});
|
|
db.application_details.count({ fileId: {$in: fileIds}}, {_id: 0, gpsTime:1, sprayStat:1, satsIn:1, lat:1, lon: 1});
|
|
|
|
// db.application_details.aggregate(
|
|
// [
|
|
// { $match: { fileId: {$in: fileIds} } },
|
|
// { $sort: { gpsTime : 1} },
|
|
// {
|
|
// $group:
|
|
// {
|
|
// _id: "Time",
|
|
// first: { $first: "$gpsTime" },
|
|
// last: { $last: "$gpsTime" }
|
|
// }
|
|
// }
|
|
// ]
|
|
// )
|
|
//
|
|
|
|
|
|
// var apps = [];
|
|
// var appC = db.applications.find({ jobId: 111}, { _id: 1 });
|
|
// appC.forEach(item => {
|
|
// apps.push(item._id);
|
|
// });
|
|
// print(apps);
|
|
// var result = db.application_details.remove({'appId':{'$in': apps}}, function() {
|
|
// });
|
|
// print(result);
|
|
// db.applications.remove({ jobId: 111});
|
|
|
|
var kmlcoors = [];
|
|
var appC = db.jobs.find({ _id: 111}, { excludedAreas: 1 });
|
|
appC.forEach(item => {
|
|
item.excludedAreas.forEach(geo => {
|
|
geo.geometry.coordinates[0].forEach(coor => {
|
|
kmlcoors.push((coor[0] + ',' + coor[1] + ',0'));
|
|
});
|
|
});
|
|
});
|
|
|
|
print(kmlcoors.join(' '));
|
|
|
|
// Change job Timestamp document field name to default
|
|
//db.jobs.update({}, { $rename : { "createDate" : "createdAt" }}, false, true );
|
|
|
|
// Find max document size in a collection
|
|
var max = 0;
|
|
db.jobs.find().forEach(function(obj) {
|
|
var curr = Object.bsonsize(obj);
|
|
if(max < curr) {
|
|
max = curr;
|
|
}
|
|
})
|
|
print(max * 1e-6 + " MB")
|
|
|
|
// Aug.16/2019
|
|
// Find orphan entities - products
|
|
var pIds = db.products.aggregate([
|
|
{
|
|
$lookup:
|
|
{
|
|
from: "users",
|
|
localField: "byPuid",
|
|
foreignField: "_id",
|
|
as: "user_detail"
|
|
}
|
|
},
|
|
{
|
|
$match: {
|
|
"user_detail": { $size: 0 }
|
|
}
|
|
},
|
|
{
|
|
$project: {
|
|
"_id": 1
|
|
}
|
|
}
|
|
]).toArray();
|
|
pIds = pIds.map(i => i._id);
|
|
// print (pIds);
|
|
// db.pilots.find({ _id : { $in: pIds } });
|
|
db.products.deleteMany({ _id : { $in: pIds } });
|
|
|
|
// 1. Update product => products with new data fields
|
|
db.products.update({ type: null }, { $set: { type: 1, restricted: false, epaReg: '' }, { multi: true } });
|
|
|
|
// 2. Create default one Water product if not any (by customer)
|
|
var userIds = db.products.aggregate([
|
|
{
|
|
$lookup:
|
|
{
|
|
from: "users",
|
|
localField: "byPuid",
|
|
foreignField: "_id",
|
|
as: "user_detail"
|
|
}
|
|
},
|
|
{
|
|
$unwind: { path: "$user_detail" }
|
|
},
|
|
{
|
|
$match: { $and:[ { name: 'Water' }, { 'user_detail.type' : 1 } ] }
|
|
},
|
|
{
|
|
$group: {
|
|
_id: '$byPuid'
|
|
}
|
|
}
|
|
]).toArray().map(i => i._id);
|
|
// print (userIds)
|
|
// db.customers.find({ user: { $nin: userIds } });
|
|
var users = db.customers.find({ user: { $nin: userIds } }, { user: 1, _id: 0 }).toArray();
|
|
var newProds = [];
|
|
for (var i = 0; i < users.length; i++) {
|
|
newProds.push({ name: 'Water', type: 9, restricted: false, epaReg: '', byPuid: users[i].user });
|
|
}
|
|
db.products.insertMany(newProds);
|
|
|
|
// 3. Update product to products for each job
|
|
var jobwProds = db.jobs.find({ $and: [ { product: { $ne: null }}, { $or: [{ products: null }, { products: { $size : 0 } } ] } ] }, { product: 1, appRate: 1, measureUnit: 1, appRateUnit: 1 }).toArray();
|
|
// db.jobs.find({ $and: [ { product: { $ne: null }}, { products: null } ] }, { appRateUnit: 1 }).toArray();
|
|
// print (jobwProds)
|
|
jobwProds.forEach(jp => {
|
|
// print ({ job: jp._id, product: jp.product, rate: jp.appRate, unit: jp.appRateUnit })
|
|
db.jobs.update({ _id: jp._id }, { $set: { products: [ { product: jp.product, rate: jp.appRate, unit: jp.appRateUnit } ] } });
|
|
});
|
|
|