-
Notifications
You must be signed in to change notification settings - Fork 0
/
profileMongoose.js
53 lines (48 loc) · 1.44 KB
/
profileMongoose.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
var mongoose = require('mongoose');
var fs = require('fs');
var profileData = JSON.parse(fs.readFileSync('public/data/kshitij.json'));
mongoose.connect('mongodb://localhost/quizRT');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (callback) {
console.log('connection open');
var profileSchema = mongoose.Schema({
userId: {type:String, unique:true},
name:String,
age:Number,
imageLink:String,
country:String,
flagLink:String,
badge:String,
totalGames:Number,
followers:Number,
following:Number,
wins:Number,
followedTopics:[],
friends:[]
},
{strict:false}
);
var Profile = mongoose.model('Profile2', profileSchema, "profile_collection");
var profile1 = new Profile({
userId : profileData.userId,
name : profileData.name,
age : profileData.age,
imageLink : profileData.imageLink,
country : profileData.country,
flagLink : profileData.flagLink,
badge : profileData.badge,
totalGames : profileData.totalGames,
followers : profileData.followers,
following : profileData.following,
wins : profileData.wins,
followedTopics : profileData.followedTopics,
friends : profileData.friends
});
profile1.save(function(err){
if ( err ) console.log(err);
console.log(profileData.name +" profile Saved Successfully");
console.log('closing mongo');
mongoose.disconnect();
});
});