-
-
Notifications
You must be signed in to change notification settings - Fork 352
/
refresh_products_tags.js
143 lines (137 loc) 路 6.4 KB
/
refresh_products_tags.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*global db*/
/*
Name : refresh_products_tags.js
Description : Refresh products_tags collection by copying *_tags fields from products collection
Version : 1.1
Usage : mongo dbname refresh_products_tags.js
Add in crontab for daily refresh :
00 02 * * * /usr/bin/mongo off /etc/mongo/refresh_products_tags.js >> /var/log/mongodb/refresh_products_tags.log
*/
print(Date() + ' : Refresh products_tags collection...');
db.products.aggregate( [
{"$project" :
{
creator:1,
countries_tags:1,
brands_tags:1,
categories_tags:1,
labels_tags:1,
packaging_tags:1,
origins_tags:1,
manufacturing_places_tags:1,
emb_codes_tags:1,
ingredients_tags:1,
additives_tags:1,
vitamins_tags:1,
minerals_tags:1,
amino_acids_tags:1,
nucleotides_tags:1,
allergens_tags:1,
traces_tags:1,
nova_groups_tags:1,
nutrition_grades_tags:1,
languages_tags:1,
creator_tags:1,
editors_tags:1,
states_tags:1,
entry_dates_tags:1,
last_edit_dates_tags:1,
codes_tags:1,
nutrient_levels_tags:1,
stores_tags:1,
informers_tags:1,
photographers_tags:1,
checkers_tags:1,
correctors_tags:1,
ingredients_from_palm_oil_tags:1,
ingredients_that_may_be_from_palm_oil_tags:1,
purchase_places_tags:1,
ingredients_n_tags:1,
pnns_groups_1_tags:1,
pnns_groups_2_tags:1,
misc_tags:1,
quality_tags:1,
unknown_nutrients_tags:1,
last_image_dates_tags:1,
cities_tags:1,
ingredients_analysis_tags:1,
popularity_tags:1,
data_sources_tags:1,
data_quality_tags:1,
data_quality_bugs_tags:1,
data_quality_info_tags:1,
data_quality_warnings_tags:1,
data_quality_errors_tags:1,
teams_tags:1,
categories_properties_tags:1,
ecoscore_tags:1,
owners_tags:1,
food_groups_tags:1,
weighers_tags:1,
}},
{"$out": "products_tags"}
]);
// estimatedDocumentCount() is available from mongodb 4.0.3
//print(Date() + ' : ' + db.products_tags.estimatedDocumentCount() + ' products refreshed in products_tags collection.');
print(Date() + ' : ' + db.products_tags.count() + ' products refreshed in products_tags collection.');
print(Date() + ' : Create indexes for products_tags collection (if not already existing)...');
db.products_tags.createIndex({creator:1}, { background: true });
db.products_tags.createIndex({countries_tags:1}, { background: true });
db.products_tags.createIndex({brands_tags:1}, { background: true });
db.products_tags.createIndex({categories_tags:1}, { background: true });
db.products_tags.createIndex({labels_tags:1}, { background: true });
db.products_tags.createIndex({packaging_tags:1}, { background: true });
db.products_tags.createIndex({origins_tags:1}, { background: true });
db.products_tags.createIndex({manufacturing_places_tags:1}, { background: true });
db.products_tags.createIndex({emb_codes_tags:1}, { background: true });
db.products_tags.createIndex({ingredients_tags:1}, { background: true });
db.products_tags.createIndex({additives_tags:1}, { background: true });
db.products_tags.createIndex({vitamins_tags:1}, { background: true });
db.products_tags.createIndex({minerals_tags:1}, { background: true });
db.products_tags.createIndex({amino_acids_tags:1}, { background: true });
db.products_tags.createIndex({nucleotides_tags:1}, { background: true });
db.products_tags.createIndex({allergens_tags:1}, { background: true });
db.products_tags.createIndex({traces_tags:1}, { background: true });
db.products_tags.createIndex({nova_groups_tags:1}, { background: true });
db.products_tags.createIndex({nutrition_grades_tags:1}, { background: true });
db.products_tags.createIndex({languages_tags:1}, { background: true });
db.products_tags.createIndex({creator_tags:1}, { background: true });
db.products_tags.createIndex({editors_tags:1}, { background: true });
db.products_tags.createIndex({states_tags:1}, { background: true });
db.products_tags.createIndex({entry_dates_tags:1}, { background: true });
db.products_tags.createIndex({last_edit_dates_tags:1}, { background: true });
db.products_tags.createIndex({codes_tags:1}, { background: true });
db.products_tags.createIndex({nutrient_levels_tags:1}, { background: true });
db.products_tags.createIndex({stores_tags:1}, { background: true });
db.products_tags.createIndex({informers_tags:1}, { background: true });
db.products_tags.createIndex({photographers_tags:1}, { background: true });
db.products_tags.createIndex({checkers_tags:1}, { background: true });
db.products_tags.createIndex({correctors_tags:1}, { background: true });
db.products_tags.createIndex({ingredients_from_palm_oil_tags:1}, { background: true });
db.products_tags.createIndex({ingredients_that_may_be_from_palm_oil_tags:1}, { background: true });
db.products_tags.createIndex({purchase_places_tags:1}, { background: true });
db.products_tags.createIndex({ingredients_n_tags:1}, { background: true });
db.products_tags.createIndex({pnns_groups_1_tags:1}, { background: true });
db.products_tags.createIndex({pnns_groups_2_tags:1}, { background: true });
db.products_tags.createIndex({misc_tags:1}, { background: true });
db.products_tags.createIndex({quality_tags:1}, { background: true });
db.products_tags.createIndex({unknown_nutrients_tags:1}, { background: true });
db.products_tags.createIndex({last_image_dates_tags:1}, { background: true });
db.products_tags.createIndex({cities_tags:1}, { background: true });
db.products_tags.createIndex({ingredients_analysis_tags:1}, { background: true });
db.products_tags.createIndex({popularity_tags:1}, { background: true });
db.products_tags.createIndex({data_sources_tags:1}, { background: true });
db.products_tags.createIndex({data_quality_tags:1}, { background: true });
db.products_tags.createIndex({data_quality_bugs_tags:1}, { background: true });
db.products_tags.createIndex({data_quality_info_tags:1}, { background: true });
db.products_tags.createIndex({data_quality_warnings_tags:1}, { background: true });
db.products_tags.createIndex({data_quality_errors_tags:1}, { background: true });
db.products_tags.createIndex({teams_tags:1}, { background: true });
db.products_tags.createIndex({categories_properties_tags:1}, { background: true });
db.products_tags.createIndex({owners_tags:1}, { background: true });
db.products_tags.createIndex({ecoscore_tags:1}, { background: true });
db.products_tags.createIndex({nutriscore_score_opposite: -1}, { background: true });
db.products_tags.createIndex({ecoscore_score: -1}, { background: true });
db.products_tags.createIndex({popularity_key: -1}, { background: true });
db.products_tags.createIndex({food_groups_tags:1}, { background: true });
print(Date() + ' : Refresh done.');