-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocessdata.js
36 lines (30 loc) · 1.22 KB
/
processdata.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
const mongoCollections=require("./config/mongoCollections");
const requiredRestaurant=mongoCollections.restaurants;
const restaurants=require("./data/restaurants");
const ObjectId = require('mongodb').ObjectId;
const dbConnection = require("./config/mongoConnection");
async function replaceReviews(){
var restaurantsCollection= await requiredRestaurant();
var ids = await restaurantsCollection.distinct('_id', {}, {});
for(var i = 0;i<ids.length;i++){
var reviews=[]
var theRestaurant=await restaurantsCollection.findOne({_id:ids[i]});
if (!theRestaurant) throw "Restaurant not found.";
for(var j = 0;j<theRestaurant.R_review.length;j++){
var theReview={
_id:new ObjectId(),
reviewer_name:theRestaurant.R_review[j].reviewer_name,
reviewer_like:theRestaurant.R_review[j].reviewer_like,
review:theRestaurant.R_review[j].review
};
reviews.push(theReview)
}
await restaurantsCollection.update(
{ _id: theRestaurant._id},
{ $set: { R_review : reviews } }
)
}
const db = await dbConnection();
await db.close();
}
replaceReviews()