-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigration.js
38 lines (33 loc) · 942 Bytes
/
migration.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
const config = require('./config')
const MongoDB = require('./mongo-database')
const collections = MongoDB(config['mongo'])
// rename key tags to downloadedTags
let action1 = function (collection) {
const selector = {}
const modifier = { $rename: { "tags": "downloadedTags" }}
return new Promise((resolve, reject) => {
collection.updateMany(selector, modifier, (err, res) => {
if (err) {
reject(err)
} else {
resolve(res)
}
})
})
}
collections['links'].apply(action1).then(console.log)
// replace null tags with empty array
let action2 = function (collection) {
const selector = {tags: null}
const modifier = {$set: {tags: []}}
return new Promise((resolve, reject) => {
collection.updateMany(selector, modifier, (err, res) => {
if (err) {
reject(err)
} else {
resolve(res)
}
})
})
}
collections['links'].apply(action2).then(console.log)