mongoose只更新数组中某一项的字段

只是需要一个特殊符号$代表匹配某一项

数据库设计如下:
在这里插入图片描述

核心代码如下:

  // 回答试题public async userPaperAnswer(request: IRequest, _h: IResponse) {const { user_paper_id, question_id, option_user } = request.payload;const updOne = await UserPaper.updateOne({ _id: user_paper_id, 'questions.question': question_id },{$set: {'questions.$.option_user': option_user,},},).catch((err) => {console.log(err);});return {code: 1,msg: '回答成功',data: updOne,};}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414986.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Koa2+Mysql搭建简易博客

http://blog.csdn.net/wclimb/article/details/77890793 转载于:https://www.cnblogs.com/SharkChilli/p/8177753.html

工作213:不能改变父组件值

父组件通过props传值给子组件,如何避免子组件改变props的属性值报错问题 报错Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s v…

uniapp移动H5在花生壳Invalid Host header

解决方案,在manifest.json中配置 "h5" : {"title" : "","domain" : "","devServer" : {"disableHostCheck" : true} }

Android 下拉式抽屉折叠动画

自定义listview工具类1、 public class ViewMeasureUtils {/*** 根据父 View 规则和子 View 的 LayoutParams,计算子类的宽度(width)测量规则** param view*/public static int getChildWidthMeasureSpec(View view, int parentWidthMeasureSpec) {// 获取父 View …

18.抽象模板方法———获取程序运行的时间

需求:获取一段程序运行的时间。原理:   获取程序开始和结束的额时间并相见即可  获取时间:System.currentTimeMillis(); 当代码完成优化后,就可以解决这类问题。这种方式,叫模板方法设计模式。 什么是模板方法呢&a…

js随机从数组中取出几个元素

这篇文章为转载,我的需求是从题库中,随机抽几道题,作为新试卷。代码如下: var items [1,2,4,5,6,7,8,9,10];1.从数组items中随机取出一个元素 var item items[Math.floor(Math.random()*items.length)];2.从前面的一篇随机数组…

工作214:结构 vue操作一个很有意思的报错 [Vue warn]: You may have an infinite update loop in a component

结构 vue操作一个很有意思的报错 [Vue warn]: You may have an infinite update loop in a component render function. 代码&#xff1a; <template><span class"show-filters" &#xff1a;class"show !show">{{ show ? 隐藏过滤器 ↑ …

Android 实现选中与非选中样式效果

drawable文件 <?xml version"1.0" encoding"utf-8"?> <selector xmlns:android"http://schemas.android.com/apk/res/android"><item android:drawable"drawable/log_button_bgok" android:state_focused"true&…

beta冲刺总结

团队成员及分工 姓名学号分工陈家权031502107前端&#xff08;消息模块&#xff09;赖晓连031502118前端&#xff08;问答模块&#xff09;雷晶031502119服务器林巧娜031502125前端&#xff08;首页模块&#xff09;一、项目预期计划及现实进展 项目预期计划现实进展解决页面异…

cesium polygon 悬浮在半空中

效果如下&#xff1a; 代码&#xff1a; let arr [[120.87140893447473, 31.877030830389447, 128.64],[120.87140872335587, 31.876963534304792, 128.64],[120.87202301763111, 31.87696299560446, 128.63],[120.87202432001283, 31.877030271988385, 128.63]]arr [].con…

工作215:点击按钮报错

获取值有点问题 点击同一按钮获取值有问题

phalcon无限重定向

问题 换了个新电脑&#xff0c;后来重新配置phalcon环境。由于用得是windows&#xff0c;而且还用得是2.0.5得版本&#xff0c;官网已经没提供这个版本下载了。而旧电脑已经被格式化了&#xff0c;?。 寻找旧版本 通过一番搜索&#xff0c;发现了一个issue&#xff0c;提到pha…

工作按钮(216):点击按钮报错--bug修复--直接写接口里面

this.title "编辑";getAction(path.join(this.url.query, id)).then(res > {this.form res.data;}).catch(err > {this.form JSON.parse(JSON.stringify(this.defaultForm));this.$message.warning("获取数据失败&#xff01;");}).finally(() &g…

cesium billboard 设置距离控制可见度

核心代码如下 viewer.entities.add({position: Cesium.Cartesian3.fromDegrees(longitude, latitude, height),billboard: {image: /imgs/disease/1.png,scaleByDistance

!KMP算法完整教程

KMP算法完整教程 全称: Knuth_Morris_Pratt Algorithm(KMP算法) 类型: 高级检索算法 功能: 字符串匹配查找 提出者: D.E.Knuth(克努兹),J.H.Morris(莫瑞…

windows安装nvm

最近mac电脑坏了&#xff0c;需要送修&#xff0c;暂时切换到windows平台进行开发。 下面安装nvm。 先保证电脑没有安装node github下载地址&#xff1a; https://github.com/coreybutler/nvm-windows/releases 找到nvm-setup.zip 下载解压安装即可。 我都是使用的默认安…

工作215:打印出父子组件的this

父亲的this VueComponent {_uid: 1842, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: VueComponent, …} $attrs: (...) $children: (2) [VueComponent, VueComponent] $createElement: ƒ (a, b, c, d) $el: div.container $listeners: (...) $options: {pare…

修改git bash主题配色和字体

这win下默认的主题令人窒息 打开git bash&#xff0c;使用命令cd ~然后用Atom命令打开文件.minttyrc.atom .minttyrc如果默认没有.minttyrc文件&#xff0c;自己新创建的也行。里面的内容填写如下&#xff1a;FontConsolas FontHeight14ForegroundColour131,148,150 Background…

jdk和maven配置

Java 1、首先准备一下文件 2、直接安装jdk&#xff0c;我是一直下一步&#xff0c;路径也是默认 3、开始配置环境变量 电脑--属性--高级--环境变量&#xff0c;新建系统变量 JAVA_HOME 和 CLASSPATH变量名&#xff1a;JAVA_HOME变量值&#xff1a;C:\Program Files\Java\…