MongoDB——增删改查
2024-10-06 22:05:38
文档结构:
{
"_id": ObjectId("5d5e5de597eb2f0b70005d1a"),
"userId": ,
"word_records": [
{
"word": "helloo",
"from": "en",
"to": "hi",
"update_time": ,
"create_time":
},
{
"word": "xx",
"from": "en",
"to": "hi",
"update_time": ,
"create_time":
}
]
}
一个用户想增加一个单词:
db.getCollection("collect_record").update({'userId':1234},{$addToSet:{word_records:{'word':'update2','to':'en','from':'hi'}}})
一个用户想删除一个单词:
db.getCollection("collect_record").update({"userId":123},{"$pull":{"word_records":{"word":"hello"}}})
分页查询某个用户的单词:
db.getCollection("collect_record").findOne({'userId':123},{'word_records':{$slice:[0,2]}})
避免重复插入:
https://blog.csdn.net/wu0che28/article/details/82316933
索引:
db.getCollection("collect_record").createIndex({
userId: NumberInt("1"),
"word_records.from": NumberInt("1"),
"word_records.to": NumberInt("1"),
"word_records.word": NumberInt("1")
}, {
name: "userId_1_word_records.from_1_word_records.to_1_word_records.word_1",
unique: true
});
最新文章
- Canvas 最佳实践(性能篇)
- [Java入门笔记] 面向对象编程基础(三):成员变量和局部变量
- NOIP2009多项式输出(水)【A004】
- js无刷新上传文件
- 菜鸟学Linux命令:cat命令 查看文件内容
- 权限控制框架Shiro简单介绍及配置实例
- 【STL+模拟】UVa 506 - System Dependencies
- Pentaho Data Integration笔记 (四):Kitchen
- 自定义QT事件
- Swift - 23 - 选择结构
- android数据库sqlite增加删改查
- java中string.trim()函数的使用
- UVA 673 Parentheses Balance (栈)
- POJ--3974 Palindrome(回文串,hash)
- 微信小程序1rpx border ios真机显示不全问题
- 使用svn进行文件和文件夹的忽略
- A1044. Shopping in Mars
- SAP跟踪前台操作导致的后台查询语句
- php -- 取整数
- sencha touch list更新单行数据
热门文章
- SQLite基础-6.运算符
- 基于Opencv快速实现人脸识别(完整版)
- RMQ+差分处理(Let Them Slide)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
- winform 中如何获取debug目录的路径
- INPUT和CONSTRUCT指令——范例报表查询,作用让用户输入数据,自动生成SQL的WHERE条件,带开窗查询
- Ansible-批量导入key(入门)
- Spring Boot源码分析-启动过程
- Codeforces 1244G. Running in Pairs
- Codeforces 1178F2. Long Colorful Strip
- 计算广告CTR预估系列(七)--Facebook经典模型LR+GBDT理论与实践