-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongoUpdateMany.js
More file actions
43 lines (33 loc) · 1.12 KB
/
mongoUpdateMany.js
File metadata and controls
43 lines (33 loc) · 1.12 KB
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
let _ = require('lodash')
let Joi = require('joi')
const moment = require('moment-timezone')
const mongo = require('@nurigo/mongo')
const keygen = require('keygenerator')
const { Pricing, BalanceHistory } = require('./models')
const mongoose = require('mongoose')
async function funB() {
try {
const conn = await mongoose.connect(`mongodb://localhost:27017/test2`, {
autoReconnect: true,
reconnectTries: 10,
reconnectInterval: 100
})
await Pricing.remove()
const list = []
for (let i = 0; i < 10000; i++) {
list.push({ accountId: 'test', countryId: i, countryName: `country_{$i}`, sms: Number(i) })
}
await Pricing.insertMany(list)
const res = await Pricing.find()
// console.log(`---------- CHECK res ----------`, res)
const result = await Pricing.updateMany({ accountId: 'test' }, { $inc: { sms: 10000 } })
console.log(`---------- CHECK result ----------`, result)
// console.log(await Pricing.find())
console.log('Success')
mongoose.connection.close()
} catch (ERR) {
console.log('check ERR', ERR)
mongoose.connection.close()
}
}
funB()