How to deal with document-oriented data
- Schema design
- Data models for e-commerce
- Nuts and bolts of databases, collection, and documents.
Principles of schema design
- What are your application access pattern?
- What's the basic unit of data? the basic unit of data is the BSON document
- What are the capabilities of your database?
- What makes a good unique id or primary key for a record?
Designing an e-commerce data model
[root@DBAMAXWELL ~]# vi user_actions.rb
require 'mongo'
VIEW_PRODUCT = 0 # action type constants
ADD_TO_CART = 1
CHECKOUT = 2
PURCHASE = 3
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'garden')
client[:user_actions].drop
actions = client[:user_actions, :capped => true, :size => 16384]
actions.create
500.times do |n| # loop 500 times, using n as the iterator
doc = {
:username => "kbanker",
:action_code => rand(4), # random value between 0 and 3, inclusive
:time => Time.now.utc,
:n => n
}
actions.insert_one(doc)
end
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"user_actions.rb" [New] 18L, 508C written
[root@DBAMAXWELL ~]# chmod 775 user_actions.rb
[root@DBAMAXWELL ~]# ruby user_actions.rb
[root@DBAMAXWELL ~]# mongo
MongoDB shell version v4.4.13
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("b9c56822-9b9a-4d7b-8a11-1e9b31be1f7b") }
MongoDB server version: 4.4.13
---
The server generated these startup warnings when booting:
2022-03-23T23:33:56.417+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> use garden
switched to db garden
> db.user_actions.count()
199
> db.user_actions.find().pretty()
{
"_id" : ObjectId("623eaf017c6c2558c3a33434"),
"username" : "kbanker",
"action_code" : 0,
"time" : ISODate("2022-03-26T06:13:21.193Z"),
"n" : 301
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33435"),
"username" : "kbanker",
"action_code" : 2,
"time" : ISODate("2022-03-26T06:13:21.195Z"),
"n" : 302
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33436"),
"username" : "kbanker",
"action_code" : 3,
"time" : ISODate("2022-03-26T06:13:21.196Z"),
"n" : 303
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33437"),
"username" : "kbanker",
"action_code" : 3,
"time" : ISODate("2022-03-26T06:13:21.197Z"),
"n" : 304
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33438"),
"username" : "kbanker",
"action_code" : 0,
"time" : ISODate("2022-03-26T06:13:21.199Z"),
"n" : 305
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33439"),
"username" : "kbanker",
"action_code" : 3,
"time" : ISODate("2022-03-26T06:13:21.201Z"),
"n" : 306
}
{
"_id" : ObjectId("623eaf017c6c2558c3a3343a"),
"username" : "kbanker",
"action_code" : 3,
"time" : ISODate("2022-03-26T06:13:21.203Z"),
"n" : 307
}
{
"_id" : ObjectId("623eaf017c6c2558c3a3343b"),
"username" : "kbanker",
"action_code" : 1,
"time" : ISODate("2022-03-26T06:13:21.204Z"),
"n" : 308
}
{
"_id" : ObjectId("623eaf017c6c2558c3a3343c"),
"username" : "kbanker",
"action_code" : 0,
"time" : ISODate("2022-03-26T06:13:21.206Z"),
"n" : 309
}
{
"_id" : ObjectId("623eaf017c6c2558c3a3343d"),
"username" : "kbanker",
"action_code" : 1,
"time" : ISODate("2022-03-26T06:13:21.208Z"),
"n" : 310
}
{
"_id" : ObjectId("623eaf017c6c2558c3a3343e"),
"username" : "kbanker",
"action_code" : 1,
"time" : ISODate("2022-03-26T06:13:21.210Z"),
"n" : 311
}
{
"_id" : ObjectId("623eaf017c6c2558c3a3343f"),
"username" : "kbanker",
"action_code" : 1,
"time" : ISODate("2022-03-26T06:13:21.212Z"),
"n" : 312
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33440"),
"username" : "kbanker",
"action_code" : 3,
"time" : ISODate("2022-03-26T06:13:21.214Z"),
"n" : 313
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33441"),
"username" : "kbanker",
"action_code" : 3,
"time" : ISODate("2022-03-26T06:13:21.216Z"),
"n" : 314
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33442"),
"username" : "kbanker",
"action_code" : 1,
"time" : ISODate("2022-03-26T06:13:21.217Z"),
"n" : 315
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33443"),
"username" : "kbanker",
"action_code" : 1,
"time" : ISODate("2022-03-26T06:13:21.219Z"),
"n" : 316
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33444"),
"username" : "kbanker",
"action_code" : 1,
"time" : ISODate("2022-03-26T06:13:21.221Z"),
"n" : 317
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33445"),
"username" : "kbanker",
"action_code" : 2,
"time" : ISODate("2022-03-26T06:13:21.223Z"),
"n" : 318
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33446"),
"username" : "kbanker",
"action_code" : 0,
"time" : ISODate("2022-03-26T06:13:21.225Z"),
"n" : 319
}
{
"_id" : ObjectId("623eaf017c6c2558c3a33447"),
"username" : "kbanker",
"action_code" : 0,
"time" : ISODate("2022-03-26T06:13:21.227Z"),
"n" : 320
}
Type "it" for more
> db.createCollection("users.actions",{capped: true, size: 16384, max: 100})
{ "ok" : 1 }
> db.reviews.createIndex({time_field: 1}, {expireAfterSeconds: 3600})
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.system.namespaces.find()
> db.system.namespaces.find();
> db.system.namespaces.find();
> db.system.indexes.find();
>
Documents and insertion
> db.numbers.save({n: 5})
WriteResult({ "nInserted" : 1 })
> db.numbers.save({n: NumberLong(5)});
WriteResult({ "nInserted" : 1 })
> db.numbers.find({n: 5});
{ "_id" : ObjectId("623ec3abe05ac712a59cc348"), "n" : 5 }
{ "_id" : ObjectId("623ec3cde05ac712a59cc349"), "n" : NumberLong(5) }
> db.numbers.find({n: {$type: 1}});
{ "_id" : ObjectId("623ec3abe05ac712a59cc348"), "n" : 5 }
> db.numbers.find({n: {$type: 18}});
{ "_id" : ObjectId("623ec3cde05ac712a59cc349"), "n" : NumberLong(5) }
>
相关文章:
How to deal with document-oriented data
Schema designData models for e-commerceNuts and bolts of databases, collection, and documents. Principles of schema design What are your application access pattern?Whats the basic unit of data? the basic unit of data is the BSON documentWhat are the ca…...
Http 状态码汇总
文章目录 Http 状态码汇总1xx(信息性状态码)2xx(成功状态码)3xx(重定向状态码)4xx(客户端错误状态码)5xx(服务器错误状态码) Http 状态码汇总 1xx(…...
mysql自定义实体类框架
根据表结构自动生产实体类和方法,根据反射与io生成,可自定义扩展方法 package com.digital.web.front; /*** pom依赖* <dependency>* <groupId>mysql</groupId>* <artifactId>mysql-connector-java</artifactId>* <version>5.1.27</ve…...
批量将Excel中的第二列内容从拼音转换为汉字
要批量将Excel中的第二列内容从拼音转换为汉字,您可以使用Python的openpyxl库来实现。下面是一个示例代码,演示如何读取Excel文件并将第二列内容进行拼音转汉字: from openpyxl import load_workbook from xpinyin import Pinyin # 打开Exce…...
消息推送:精准推送,提升运营效果,增添平台活力
对于app开发者而言,没有什么途径比消息推送更能直接、即时地触及目标用户群体了。消息推送与我们的日常生活息息相关,各种APP的状态和通知都通过消息推送来告知用户,引起用户的注意,吸引用户点开app。总而言之,推送服务…...
[保研/考研机试] KY43 全排列 北京大学复试上机题 C++实现
题目链接: 全排列https://www.nowcoder.com/share/jump/437195121692001512368 描述 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列。 我们假设对于小写字母有a < b < ... < y < z,而且给定的字符串中的字…...
Java将时间戳转化为特定时区的日期字符串
先上代码: ZonedDateTime dateTime ZonedDateTime.ofInstant(Instant.ofEpochMilli(System.currentTimeMillis()),zone ); //2019-12-01T19:01:4608:00String formattedDate dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd") ); //2019-12-…...
【算法挨揍日记】day03——双指针算法_有效三角形的个数、和为s的两个数字
611. 有效三角形的个数 611. 有效三角形的个数https://leetcode.cn/problems/valid-triangle-number/ 题目描述: 给定一个包含非负整数的数组 nums ,返回其中可以组成三角形三条边的三元组个数。 解题思路: 本题是一个关于三角形是否能成立…...
通过 kk 创建 k8s 集群和 kubesphere
官方文档:多节点安装 确保从正确的区域下载 KubeKey export KKZONEcn下载 KubeKey curl -sfL https://get-kk.kubesphere.io | VERSIONv3.0.7 sh -为 kk 添加可执行权限: chmod x kk创建 config 文件 KubeSphere 版本:v3.3 支持的 Kuber…...
感觉和身边其他人有差距怎么办?
虽然清楚知识需要靠时间沉淀,但在看到自己做不出来的题别人会做,自己写不出的代码别人会写时还是会感到焦虑怎么办? 你是否也因为自身跟周围人的差距而产生过迷茫,这份迷茫如今是被你克服了还是仍旧让你感到困扰? 下…...
【C语言基础】宏定义的用法详解
📢:如果你也对机器人、人工智能感兴趣,看来我们志同道合✨ 📢:不妨浏览一下我的博客主页【https://blog.csdn.net/weixin_51244852】 📢:文章若有幸对你有帮助,可点赞 👍…...
微服务系列文章之 SpringBoot 最佳实践
Spring Boot 是一种广泛使用且非常流行的企业级高性能框架。 以下是一些最佳实践和一些技巧,我们可以使用它们来改进 Spring Boot 应用程序并使其更加高效。 Spring Boot 的四大核心 1、自动配置 针对很多Spring应用程序和常见的应用功能,Spring Boo…...
C++并发多线程--std::async、std::packaged_task和std::promise的使用
目录 1--std::async的使用 2--std::packaged_task的使用 3--std::promise的使用 1--std::async的使用 std::async用于启动一个异步任务,并返回一个std::future对象;std::future对象里含有异步任务线程入口函数的结果; std::launch::deferr…...
opencv-目标追踪
import argparse import time import cv2 import numpy as np# 配置参数 ap argparse.ArgumentParser() ap.add_argument("-v", "--video", typestr,help"path to input video file") ap.add_argument("-t", "--tracker", …...
【数据结构】 单链表面试题讲解
文章目录 引言反转单链表题目描述示例:题解思路代码实现: 移除链表元素题目描述:示例思路解析: 链表的中间结点题目描述:示例:思路解析代码实现如下: 链表中倒数第k个结点题目描述示例思路解析&…...
C++ string类的模拟实现
模拟实现string类不是为了造一个更好的轮子,而是更加理解string类,从而来掌握string类的使用 string类的接口设计繁多,故而不会全部涵盖到,但是核心的会模拟实现 库中string类是封装在std的命名空间中的,所以在模拟…...
Qt实现简单的漫游器
文章目录 Qt的OpenGL窗口GLSL的实现摄像机类的实现简单的漫游器 Qt的OpenGL窗口 Qt主要是使用QOpenGLWidget来实现opengl的功能。 QOpenGLWidget 提供了三个便捷的虚函数,可以重载,用来重新实现典型的OpenGL任务: paintGL:渲染…...
【c语言】文件操作
朋友们,大家好,今天分享给大家的是文件操作的相关知识,跟着我一起学习吧!! 🎈什么是文件 磁盘上的文件是文件。 但是在程序设计中,我们一般谈的文件有两种:程序文件、数据文件 程序文…...
【Unity】坐标转换经纬度方法(应用篇)
【Unity】坐标转换经纬度方法(应用篇) 解决地图中经纬度坐标转换与unity坐标互转的问题。使用线性变换的方法,理论上可以解决小范围内所以坐标转换的问题。 之前有写过[Unity]坐标转换经纬度方法(原理篇),在实际使用中,…...
element时间选择器el-date-picter使用disabledDate指定禁用的日期
需要的效果 <el-date-pickerclass"selectstyle"v-model"year"value-format"yyyy"type"year":picker-options"disabledCli"placeholder"选择年"> </el-date-picker>data() {return {disabledCli: {/…...
OpenClaw隐私保护:GLM-4.7-Flash本地处理敏感数据的实践方案
OpenClaw隐私保护:GLM-4.7-Flash本地处理敏感数据的实践方案 1. 为什么需要本地化AI处理敏感数据? 去年我在处理公司财务报告自动化时遇到一个棘手问题:使用云端AI服务需要上传包含客户隐私的Excel文件到第三方服务器。尽管服务商承诺数据安…...
Luau数据流分析技术:如何实现精准的类型推断
Luau数据流分析技术:如何实现精准的类型推断 【免费下载链接】luau A fast, small, safe, gradually typed embeddable scripting language derived from Lua 项目地址: https://gitcode.com/gh_mirrors/lu/luau Luau是一种快速、小巧、安全且支持渐进类型化…...
如何快速掌握React Email Editor:深入理解拖拽邮件编辑器的实现原理
如何快速掌握React Email Editor:深入理解拖拽邮件编辑器的实现原理 【免费下载链接】react-email-editor Drag-n-Drop Email Editor Component for React.js 项目地址: https://gitcode.com/gh_mirrors/re/react-email-editor React Email Editor是一个功能…...
云原生实战:如何用GROUP模型提升容器工作负载预测准确率(附避坑指南)
云原生实战:如何用GROUP模型提升容器工作负载预测准确率(附避坑指南) 在云原生架构中,容器资源管理一直是DevOps团队面临的重大挑战。传统单容器预测方法往往忽视了微服务间复杂的协同关系,导致预测误差居高不下。本文…...
逆向工程必备:用aardio和Sunny中间件抓取手机App封包的3种实战姿势
逆向工程实战:aardio与Sunny中间件的移动端封包拦截艺术 在移动应用安全研究领域,封包拦截与分析是理解应用通信逻辑的关键入口。不同于传统的PC端抓包,移动环境面临着证书绑定、代理检测等更复杂的防御机制。aardio配合Sunny中间件构建的轻量…...
手把手教你用LVGL特殊符号打造炫酷UI界面
手把手教你用LVGL特殊符号打造炫酷UI界面 在嵌入式设备开发中,UI设计往往面临资源受限的挑战。LVGL(Light and Versatile Graphics Library)作为一款轻量级开源图形库,通过其丰富的特殊符号系统,让开发者能够在有限资…...
AD21实战:3种方法搞定Keepout和机械层互转,最后一种能救急
AD21实战:3种高效解决Keepout与机械层互转难题的方法 在PCB设计过程中,Keepout层和机械层的正确使用与转换是确保设计准确性的关键环节。许多工程师都遇到过这样的困境:当设计文件中包含复杂图形元素时,简单的层切换或属性批量修…...
零基础入门esp32开发:用快马平台生成第一个led控制程序详解
最近在学ESP32开发,发现对于新手来说,从零开始写代码还是挺有挑战的。不过我发现了一个超好用的工具——InsCode(快马)平台,它可以根据你的需求直接生成可运行的代码,特别适合像我这样的初学者。 项目需求分析 我想实现一个简单的…...
医学图像分类实战:基于kvasir v2胃病数据集的深度卷积网络性能对比
1. 医学图像分类与KVASIR V2数据集简介 胃镜图像分类是计算机辅助诊断系统中的关键环节。KVASIR V2作为目前最全面的公开胃病数据集,包含8类常见胃部病变的8000张高清图像,每类1000张。这些图像由专业胃肠病专家标注,覆盖了从正常黏膜到早期…...
SemanticKITTI数据集评测:DarkNet53Seg、PointNet++等模型谁更强?附复现代码
SemanticKITTI点云语义分割实战:模型选型与性能优化指南 点云语义分割技术正在重塑自动驾驶、机器人导航和三维场景理解等领域的研究范式。作为该领域最具挑战性的基准之一,SemanticKITTI数据集凭借其大规模、高密度标注和真实场景多样性,已成…...
