-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateRIDs.js
53 lines (50 loc) · 1.53 KB
/
createRIDs.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
var mongodb = require('mongodb');
var mongoserver = new mongodb.Server('10.112.0.110', 26374);
//var mongoserver = new mongodb.Server('localhost', 26374);
var dbConnector = new mongodb.Db('uenergy', mongoserver);
// USAGE node removeYouTubeURL STRING artist INT postionInTopTracks INT newPositionInTopTracks
dbConnector.open(function(err, db) {
if(err) {
console.log(err.message);
} else {
db.collection('artistLocations2', function(err,col){
if (err){
console.log(err);
}
else{
var cursor = col.find({'RID':{'$exists':false}});
cursor.count(function(err,count){
if(err) console.log('count error');
console.log(count + ' artists');
cursor.each(function(err,artist){
if(err) console.log(err)
else if(artist != null){
var top = artist.topTracks;
var i; var flag = false;
for(i = 0; i < top.length; i++){
if(top[i].RID == null){
top[i]['RID'] = top[i].video_id;
flag = true;
}
}
var settingness = {}
if(flag)
settingness['topTracks'] = top;
if(artist.RID == null){
settingness['RID'] = artist.echoID;
flag = true;
}
if(flag){
col.findAndModify({'echoID' : artist.echoID}, [['_id', 'asc']], {
$set : settingness},{safe:true}, function(err) {
if(err) {
console.log(err.message);
}
else{ console.log(artist.name + ' = success'); count--; if(count == 0) process.exit();}
});}
}
});});
}
});
}
});