-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_script.js
More file actions
106 lines (95 loc) · 2.63 KB
/
edit_script.js
File metadata and controls
106 lines (95 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var request = require('request');
var cheerio = require('cheerio');
var URL = require('url-parse');
const mongoose = require('mongoose');
var rn = require('random-number');
var options = {
min: 30
, max: 400
, integer: true
}
//const config = require('./config/database');
//const Medicine = require('./models/medicine');
// var mongoose = require("mongoose");
// mongoose.connect("mongodb://localhost:27019/pharma_database");
// var db = mongoose.connection;
const MedicineSchema = mongoose.Schema(
{
Name:String,
Company:String,
Salt0:String,
Salt1:String,
Salt2:String,
Salt3:String,
Combinations:String,
Volume:String,
Presentation:String,
Price: Number
},
{
collection: 'medicines'
}
);
var Model = mongoose.model('Medicines', MedicineSchema);
mongoose.connect('mongodb://localhost:27021/test');
change_price();
change_salt();
// change_price();
function change_price(){
// Model.find({"Price":-1},function(err,result){
// if (err) throw err;
// result.Price=rn(options);
// result.save(function(err){
// if (err) throw err;
// console.log("Updated");
// });
// });
Model.update({"Price":-1},{$set: {"Price":rn(options)}},{multi: true},function(err, result){
if (err) throw err;
console.log("Updated");
});
// Model.find({"Price":},function(err,result){
// if (err) throw err;
// console.log(result);
// });
}
//db.medicines.update({"Price":NaN},{$set: {"Price":99}})
function change_salt(){
Model.find({},{Salt0:1, Salt1:1, Salt2:1, Salt3:1},function(err,result){
var count=0;
for(var i=0;i<result.length;i++)
{
var str=result[i].Salt0;
if(str[0]==" "){
str=str.slice(1,str.length)
}
if(str[str.length-1]==" "){
str=str.slice(0,str.length-1);
}
var str1=result[i].Salt1;
if(str1[0]==" "){
str1=str1.slice(1,str1.length)
}
if(str1[str1.length-1]==" "){
str1=str1.slice(0,str1.length-1);
}
var str2=result[i].Salt2;
if(str2[0]==" "){
str2=str2.slice(1,str2.length)
}
if(str2[str2.length-1]==" "){
str2=str2.slice(0,str2.length-1);
}
var str3=result[i].Salt3;
if(str3[0]==" "){
str3=str3.slice(1,str3.length)
}
if(str3[str3.length-1]==" "){
str3=str3.slice(0,str3.length-1);
}
Model.update({"_id":result[i]._id},{$set:{"Salt0":str, "Salt1":str1, "Salt2":str2, "Salt3":str3}}, function(err, res){
if (err) throw (err);
});
}
});
}