-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind duplicates.js
75 lines (52 loc) · 1.44 KB
/
find duplicates.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
// let stuff = []
var duplicates = db.getCollection('osrs_items').aggregate([
{$group: {
_id: "$name",
uniqueIds: {$addToSet: "$_id"},
count: {$sum: 1}
}
},
{$match: {
count: {"$gt": 1}
}
},
{$sort: {
count: -1
}
}
])
duplicates = duplicates['_batch']
var duplicateNames = duplicates.map(duplicate => duplicate._id)
print("Num duplicates " + duplicateNames.length)
print(duplicateNames)
var buyLimitTrue = []
for (let i=0; i < duplicateNames.length; i++){
print(duplicateNames[i])
var butLimitItem = db.getCollection('osrs_items').aggregate([
{$match:{
name:duplicateNames[i],
"stats.buy_limit":{'$ne': null}
}
}
])
print(butLimitItem._batch)
if (butLimitItem._batch.length > 0){
buyLimitTrue.push(butLimitItem._batch[0])
}
}
print(buyLimitTrue)
var goodItems = []
for (let i =0; i < buyLimitTrue.length; i++){
var goodItem = {
name:buyLimitTrue[i].name,
uniqueID:buyLimitTrue[i].uniqueID,
stats:buyLimitTrue[i].stats,
}
goodItems.push(goodItem)
var stringName = '"' + goodItem.name + '"'
print(stringName)
// db.getCollection('osrs_items').deleteMany({name:stringName})
}
for (let i =0; i < goodItems.length; i++){
db.getCollection('osrs_items').insert(goodItems[i])
}