我有一个员工架构:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const EmployeesSchema = new Schema({
EmployeeId: {
type: String,
required: true
},
// .... more attributes
Copies: {
type: Number,
required: true
InsertDate: {
type: Date,
default: Date.now
}
});
module.exports = Employees = mongoose.model(
"employees",
EmployeesSchema
);
和id数组...
const _ids = // I get this one from some code manipulation - return the `_id` attribute
我想通过一个属性-_ids
更新Copies
中的那些文档:
await Employees.update(
{
_id: {
$in: _ids
}
},
{
$set: { Copies: Copies - 1 } // here it looks for a var called Copies
},
{ multi: true }
);
如何根据每个文档的1
值从Copies
属性中减少Copies
?