-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.js
62 lines (56 loc) · 1.82 KB
/
user.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
54
55
56
57
58
59
60
61
62
const mongoose = require('mongoose');
const mock = require('mockjs');
const random = mock.Random;
// const mongodb = new mongoose();
const conn = mongoose.connect('mongodb://127.0.0.1/local');
// schema
const schema = mongoose.Schema,
objectId = schema.ObjectId;
const userSchema = new schema({
uuid: String,
salt: String,
username: {type: String},
account: {type: String},
password: {type: String},
depth: {type: Number},
is_proxy: Number,
percentage: Number,
status: Number,
created_at: Date,
created_by: Number,
created_name: String,
remark: String
});
// console.log(objectId);
// 肯定是连接创建模型啦
const userModel = mongoose.model('user', userSchema, 'user');
/* userModel.create({username: random.cname(), password: '7259650e64b768a00c805891b429741d', depth: 1, percentage: 90, is_proxy: 1}, function (err,user){
console.log(err);
}) */
let set = new Set();
userSchema.pre('save', function (next) {
console.log('正在保存,请等待。。。。');
next();
})
for (let i = 0; i < 10; i++) {
set.add({uuid: random.word(), salt: 'LzyC',username: random.cname(), account: random.word(8,12), password: '7259650e64b768a00c805891b429741d', depth: random.integer(1,10), percentage: 90, is_proxy: 1})
}
// 遍历转成数组
let users = [...set];
userModel.insertMany(users, function (err) {
console.log(err)
})
/**
id Integer
username VarChar(200) 代理名称
password VarChar(256) 密码
depth Integer 0 代理深度
is_proxy TinyInt 0 是否是代理(1-yes, 0-no)
status TinyInt 是否禁用
percentage Numeric(10, 1) 分成比例
created_at TimeStamp 创建时间
created_by Integer 创建人
created_name VarChar(200) 创建人名称(管理员创建为空)
remark Text 备注
*/
//7259650e64b768a00c805891b429741d