forked from beilunyang/dhtCrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.js
More file actions
28 lines (21 loc) · 755 Bytes
/
model.js
File metadata and controls
28 lines (21 loc) · 755 Bytes
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
'use strict';
const mongoose = require('mongoose');
const config = require('./config');
mongoose.connect(config.db);
const db = mongoose.connection;
db.on('error', () => console.log('mongodb connect fail'));
db.once('open', () => console.log('mongodb connect success'));
const InfoHashSchema = mongoose.Schema({
info_hash: String
});
InfoHashSchema.index({info_hash: 1}, {unique: true});
const InfoHash = mongoose.model('InfoHash', InfoHashSchema);
exports.saveInfoHash = function (hash) {
const infoHash = new InfoHash({info_hash: hash});
infoHash.save((err, infoHash) => {
if (err) {
return console.error('save infohash failed');
}
console.log('successfully save infohash: %s', infoHash.info_hash);
});
}