-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateTypes.mongodb
89 lines (84 loc) · 1.58 KB
/
updateTypes.mongodb
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
use("mongogram")
/*
db.messages.updateMany(
{
date_unixtime: {$exists: true}
},
[
{$set: {
date_unixtime_proper: {$toLong: "$date_unixtime"},
}},
{$set: {
date_unixtime_proper: {$multiply: ["$date_unixtime_proper", 1000]},
}},
{$set: {
date: {$toDate: "$date_unixtime_proper"}
}},
{$unset: [
"date_unixtime",
"date_unixtime_proper"
]}
]
)
db.messages.updateMany(
{
from: {$exists: true}
},
[
{$set: {
actor: "$from"
}},
{$unset: [
"from",
]}
]
)
db.messages.updateMany(
{
from_id: {$exists: true}
},
[
{$set: {
actor_id: "$from_id"
}},
{$unset: [
"from_id",
]}
]
)
*/
db.messages.updateMany(
{
text: {$type: "array"},
},
[
{$set: {
rawText: {
$reduce: {
input: "$text",
initialValue: "",
in: {$concat: [
"$$value",
{$cond: {
if: {$eq: [{$type: "$$this"}, "object"]},
then: "$$this.text",
else: "$$this",
}},
]}
}
}
}},
]
)
/*
db.messages.updateMany(
{
text: {$type: "string"},
},
[
{$set: {
rawText: "$text",
}},
]
)
*/