由于某些原因,我不能使用mongoose和typescript通过id更新文档。我正在测试api并将id作为参数传入。 我尝试了几种不同的按ID更新的方法。我可以通过比较任何其他字段来更新,但我需要按ID更新 //This is the controller
import DfrModel from './dfr.model';
import { Request, Response } from 'express';
import config from '../../config/config';
import bodyParser = r
是否可以使用另一个字段的值更新字段?
这是我的模式
var timeSchema = new mongoose.Schema({
hours: Number,
minutes: Number
});
module.exports = mongoose.model("Time", timeSchema);
当分钟变为0时,我希望分钟的值为小时* 60。
这是我的密码
Time.updateMany({}, {minutes: hours * 60});
我的代码抛出一个错误,上面写着hours is not defined
有没有可能使用小时的值来更新分钟?
我有mongodb "Mydb“和集合”用户“。
export let User = mongoose.model("User", UserSchema);
let UserSchema = new mongoose.Schema({
phone : {
type : String,
validate: {
现在,我想更新字段"phone“,以取代空白空间(例如)。我试着使用以下方法:
User.update({}, {$set : {'phone': //here is m