mongodb更新数组中的所有匹配项
假如集合中有如下数据
{ "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC",
"comments" : [ { "by" : "joe", "votes" : 3 }, { "by" : "jane", "votes" : 7 } ] }
将comments值中所有votes的值改为1
t.update( obj, {$set:{'comments.$.votes':1}}, false, true )
结果为:
{ "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC",
"comments" : [ { "by" : "joe", "votes" : 1 }, { "by" : "jane", "votes" : 1 } ] }
mongodb更新数组中的所有匹配项的更多相关文章
- MongoDB 更新数组中的元素
本文记录如何更新MongoDB Collection 中的Array 中的元素.假设Collection中一条记录格式如下: 现要删除scores 数组中,"type" 为 &qu ...
- php 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等
/** * 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等 * @param $id * @param $ids * @param string $returnstr * @ret ...
- Mongodb更新数组$pull修饰符 (mongodb 修改器($inc/$set/$unset/$push/$pop/upsert))
mongodb 修改器($inc/$set/$unset/$push/$pop/upsert)) https://www.jb51.net/article/112588.htm http://bl ...
- Mongodb更新数组$pull修饰符
http://blog.csdn.net/yaomingyang/article/details/78701643 一.$pull修饰符会删除掉数组中符合条件的元素,使用的格式是: { $pull: ...
- mongodb对数组中的元素进行查询详解
原文链接:http://blog.csdn.net/renfufei/article/details/78320176 MongoDB中根据数组子元素进行匹配,有两种方式. 使用 “[数组名].[子元 ...
- MongoDB实现数组中重复数据删除
这个功能真的是写死我了,对于MongoDB一点都不熟悉,本来想使用spring与MongoDB的融合mongoDBTemplate,发现压根不是web项目,懒得配置那些配置文件,就使用最原始的数据库操 ...
- mongodb更新数组元素中的字段,数组$占位符
pppCodes为数组,PPPCode,expiredOn为数组元素中的字段 db.getCollection('users').findOneAndUpdate({ _id: userId, 'pp ...
- leetcode 442. Find All Duplicates in an Array 查找数组中的所有重复项
https://leetcode.com/problems/find-all-duplicates-in-an-array/description/ 参考:http://www.cnblogs.com ...
- js下拉框:从数组中筛选出匹配的数据
handleChange(val) { let obj = {} // 遍历数组 obj = this.options.find(item => { // 筛选出匹配的数据 return ite ...
随机推荐
- Domino中使用JAVA代理
Domino中使用JAVA代理一定要小心,特别是R5的版本. 1.及时地对所用到Notes Object(session,agentContext,db,view,document. 等等)进行Rec ...
- 基于springboot的多数据源配置
发布时间:2018-12-11 技术:springboot1.5.1 + maven3.0.1+ mybatis-plus-boot-starter2.3.1 + dynamic-datasour ...
- ios中asihttprequest 下载缓存
asi中下载缓存第一种方法 #import <UIKit/UIKit.h> #import "ASIHTTPRequest.h" #import "ASIDo ...
- (原)luarocks install 提示 failed fetching manifest
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6400169.html 参考网址: https://github.com/torch/torch7/is ...
- [转载]eclipse自动同步插件filesync的使用
原文地址:eclipse自动同步插件filesync的使用作者:老孙丢了金箍棒 这篇文章和之前我写的<eclipse下自动部署WEB项目>根本目的是一样的,只是达到目的的方式不同. ...
- 无法启动程序,因为计算机丢失D3DCOMPILER_47.dll 的解决方法
这个原因应该是windows update在更新的时出现错误导致的 解决方法是安装 KB4019990 更新包. 网址如下:http://www.catalog.update.microsoft.c ...
- NYOJ------汉诺塔(一)
汉诺塔(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度 ...
- jenkins 图文教程 下载 --》安装--》更改默认端口号,附自启动脚本
参考文章: 1.http://www.ibm.com/developerworks/cn/java/j-lo-jenkins/ 2.http://blog.csdn.net/zhaolixin007/ ...
- 如何查看出口IP地址?
出口ip地址怎么看?#curl ifconfig.me
- Error 25007.初始化合成时发生错误。安装程序无法使用 LoadLibraryShim() 加载合成。
安装“Microsoft .NET Framework 2.exe”报错如下: c:\windows\microsoft.net\framework\...类似这种错误都因 .NET Framewor ...