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 ...
随机推荐
- rhel7.x配置本地yum
转载:http://www.mvpbang.com/articles/2017/12/22/1513948827684.html rhel7.x配置本地yum 环境: centos7.4 vmarew ...
- 【TP3.2】TP3.2下实现ajax分页(原创+亲测可用)
一,写在最开始:ajax分页的原理,是利用了js的ajax执行请求,获取分页list和分页page [代码块],去替换页面显示数据的[代码块] 技术:js的ajax + TP3.2的fetch(&qu ...
- 系统空间占用排查 tomcat超大日志catalina.out 删除 与df 状态更新
二.catalina.out占用多达60+G 并且其他诸如catalina.2016-03-29.log等具体日期的日志文件,个别的也有10G左右,直接删除这些大个头.df看稍有改善.针对catali ...
- (原)ubuntnu中anaconda的g++提示crtbeginS.o:unrecognized relocation
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6950263.html 自从使用anaconda后,方便是方便了,也遇到了很多蛋疼的问题. 这次使用an ...
- linux shell 脚本攻略学习10--生成任意大小的文件和文本文件的交集与差集详解
一.生成任意大小的文件(dd命令): 举例: amosli@amosli-pc:~/learn/example$ ; + records in + records out bytes ( MB/s a ...
- Linux提示“libc.so.6: version `GLIBC_2.14' not found”系统的glibc版本太低
http://www.linuxidc.com/Linux/2017-01/139806.htm http://www.linuxidc.com/Linux/2015-04/116472.htm
- html5界面手机播放mp3
1把这段代码复制到htm5界面. <audio id="audio" src="2.mp3" style="opacity:0" pr ...
- ubuntu(14.04) 下配置重写
1.开启rewrite模块,使用命令:a2enmod rewrite 2.在apache2.conf,配置你网站的目录(是目录而定)
- 安装Nginx+Tomcat
Centos下安装nginx rpm包 1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/packages/centos/ http://nginx.org/e ...
- 让Label等控件支持HTML格式的代码? 使用NSAttributedString:
> 如何让Label等控件支持HTML格式的代码? 使用NSAttributedString: NSString *htmlString = @"<div>Tate< ...