文档结构:

{
"_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
});

最新文章

  1. Canvas 最佳实践(性能篇)
  2. [Java入门笔记] 面向对象编程基础(三):成员变量和局部变量
  3. NOIP2009多项式输出(水)【A004】
  4. js无刷新上传文件
  5. 菜鸟学Linux命令:cat命令 查看文件内容
  6. 权限控制框架Shiro简单介绍及配置实例
  7. 【STL+模拟】UVa 506 - System Dependencies
  8. Pentaho Data Integration笔记 (四):Kitchen
  9. 自定义QT事件
  10. Swift - 23 - 选择结构
  11. android数据库sqlite增加删改查
  12. java中string.trim()函数的使用
  13. UVA 673 Parentheses Balance (栈)
  14. POJ--3974 Palindrome(回文串,hash)
  15. 微信小程序1rpx border ios真机显示不全问题
  16. 使用svn进行文件和文件夹的忽略
  17. A1044. Shopping in Mars
  18. SAP跟踪前台操作导致的后台查询语句
  19. php -- 取整数
  20. sencha touch list更新单行数据

热门文章

  1. SQLite基础-6.运算符
  2. 基于Opencv快速实现人脸识别(完整版)
  3. RMQ+差分处理(Let Them Slide)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
  4. winform 中如何获取debug目录的路径
  5. INPUT和CONSTRUCT指令——范例报表查询,作用让用户输入数据,自动生成SQL的WHERE条件,带开窗查询
  6. Ansible-批量导入key(入门)
  7. Spring Boot源码分析-启动过程
  8. Codeforces 1244G. Running in Pairs
  9. Codeforces 1178F2. Long Colorful Strip
  10. 计算广告CTR预估系列(七)--Facebook经典模型LR+GBDT理论与实践