-
Notifications
You must be signed in to change notification settings - Fork 10
/
mongo_operations
executable file
·102 lines (81 loc) · 3.98 KB
/
mongo_operations
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
apt update
apt upgrade
http://localhost/GoGoCarto/web/app_dev.php/elements/update-colibris-lmc/export_lmc_1.csv
use gogocarto_default
db.Element.deleteMany({"sourceKey":"LMC"})
db.Element.updateMany({"sourceKey":"gogocarto"}, {$set: {"sourceKey":"PDCN"}})
db.Element.updateMany( { } , { $rename: { 'coordinates': 'geo', 'tel': 'telephone', 'mail': 'email', 'webSite': 'website' } } )
db.Element.updateMany( { } , { $rename: { 'address': 'fullAddress' } } )
db.Element.updateMany( { } , { $rename: { 'city': 'address.addressLocality', 'postalCode': 'address.postalCode', 'streetAddress':'address.streetAddress' } } )
db.Element.updateMany( { } , { $rename: { 'geo.lat': 'geo.latitude', 'geo.lng': 'geo.longitude' } } )
db.Element.updateMany({}, {$set: {"address.addressCountry":"FR"}})
// doublons
db.Element.updateMany({'address.addressLocality':null, 'status': { $gte: -3}}, {$set: {"status":-6}})
db.Element.updateMany({'geo.latitude':0}, {$set: {"moderationState":-2}})
db.UserInteractionContribution.deleteMany({"status":-2, "statusChangedAt": { $gte: ISODate("2017-12-12T00:00:00.000Z")}})
// votes depuis ouverture
db.UserInteractionVote.find({'createdAt': { $gte: ISODate("2017-11-28T00:00:00.000Z")}})
db.UserInteractionContribution.find({"status":-2, "statusChangedAt": { $gte: ISODate("2017-12-12T00:00:00.000Z")}}).count()
db.User.find({'email':null}).count()
db.User.find({'facebookUid': { $ne: null}}).count()
db.Element.aggregate(
{"$group" : { "_id": "$name", uniqueIds: { $addToSet: "$_id" },"count": { "$sum": 1 } } },
{"$match": { "_id" :{ "$ne" : null } , "count" : {"$gt": 1} } },
{"$project": {"name" : "$_id", "_id" : 0, "uniqueIds" : "$uniqueIds", "status": "$status"} }
)
db.Element.aggregate([
{
$unwind: "$contributions"
},
{
$lookup:
{
from: "UserInteractionContribution",
localField: "contributions",
foreignField: "_id",
as: "contribs"
}
},
{"$match": { "moderationState" :-2 } },
{"$project": {"name" : 1, "contribs": 1} }
])
db.Element.aggregate([
{
$lookup:
{
from: "UserInteractionContribution",
localField: "contributions",
foreignField: "id",
as: "contribs"
}
},
{"$match": { "moderationState" :-2 } },
{"$project": {"name" : 1, "contribs": "$contribs"} }
])
# create script.js with :
db.Element.find({'moderationState':-2}).forEach(function(x){
x.fetch();
print(x.contributions.userMail+",");
});
# or other script
db.User.find({'email': { $ne: '' }},{'mail':1, '_id':0}).forEach(function(x){
print(x.email+",");
});
# then run
mongo gogocarto_default script.js > export.csv
# and copy it to your machine
scp admin@colibris_prod:/home/admin/export.csv local-export-copy.csv
db.Category.updateOne({depth: 0}, {$set: {isMainNode:true}})
db.Category.updateMany({}, { $unset: { depth: "", isFixture: "" } })
db.UserInteraction.updateMany( { } , { $rename: { 'userMail': 'userEmail' } } )
db.UserInteractionContribution.updateMany( { } , { $rename: { 'userMail': 'userEmail' } } )
db.UserInteractionVote.updateMany( { } , { $rename: { 'userMail': 'userEmail' } } )
db.UserInteractionReport.updateMany( { } , { $rename: { 'userMail': 'userEmail' } } )
db.User.updateMany( {}, { $set: { 'lastNewsletterSentAt' : ISODate("2018-03-27T00:00:00.000Z") } })
db.Element.updateMany( { } , { $rename: { 'fullJson': 'baseJson' } } )
db.Element.deleteMany({'createdAt': { $gte: ISODate("2018-06-11T00:00:00.000Z")}})
db.Category.updateMany( { } , { $rename: { 'isMainNode': 'isRootCategory' } } )
db.Category.updateMany( { } , { $rename: { 'displayCategoryName': 'displayInMenu' } } )
db.Option.updateMany({}, { $unset: { displayOption: "" } })
# Convert static data to new customizable fields
db.Element.updateMany( { } , { $rename: { 'website': 'data.website', 'telephone':'data.telephone', 'commitment':'data.commitment', 'description':'data.description', 'descriptionMore':'data.descriptionMore', 'openHoursMoreInfos':'data.openHoursMoreInfos', 'urls':'data.urls' } } )