-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubcategories.js
35 lines (25 loc) · 1.08 KB
/
subcategories.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
MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/agilemoves-dev', function(err, db) {
if(!err) {
console.log("We are connected");
}
var cursor = db.collection('trainingcards').find({});
cursor.each(function(err, trainingcard) {
if (err) console.log("trainingcard cannot be read");
if(trainingcard == null) {
return 0;
}
if(trainingcard.category != null && trainingcard.category != undefined) {
db.collection('categories').findAndModify({name:trainingcard.category}, [['name', 1]], {name:trainingcard.category}, {new:true, upsert: true}, function(err, doc) {
if(err) console.log(err);
console.log("docccc = " + doc);
});
//db.collection('trainingcards').update({_id: trainingcard._id}, {
// $unset : { 'category' : '' }}, function (err, updated) {
//
// if (err) throw err;
// console.dir(updated + " trainingcard Updated!");
//});
}
});
});