mirror of
https://github.com/journey-ad/Moe-Counter.git
synced 2024-12-01 02:27:22 +01:00
3bd1ae58e4
feat: support dynamic image size docs: add Readme.md
36 lines
644 B
JavaScript
36 lines
644 B
JavaScript
'use strict'
|
|
|
|
const mongoose = require('mongoose')
|
|
const schema = require('./schema')
|
|
|
|
mongoose.connect(process.env.DB_URL, {
|
|
useNewUrlParser: true,
|
|
useUnifiedTopology: true,
|
|
useFindAndModify: false
|
|
})
|
|
|
|
const Count = mongoose.connection.model('Count', schema)
|
|
|
|
function getNum(name) {
|
|
return Count
|
|
.findOne({ name }, '-_id -__v')
|
|
.exec()
|
|
}
|
|
|
|
function getAll() {
|
|
return Count
|
|
.find({ }, '-_id -__v')
|
|
.exec()
|
|
}
|
|
|
|
function setNum(name, num) {
|
|
return Count
|
|
.findOneAndUpdate({ name }, { name, num }, { upsert: true })
|
|
.exec()
|
|
}
|
|
|
|
module.exports = {
|
|
getNum,
|
|
getAll,
|
|
setNum
|
|
} |