当前位置: 首页 > news >正文

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&#xff08…...

mysql自定义实体类框架

根据表结构自动生产实体类和方法,根据反射与io生成,可自定义扩展方法 package com.digital.web.front; /*** pom依赖* <dependency>* <groupId>mysql</groupId>* <artifactId>mysql-connector-java</artifactId>* <version>5.1.27</ve…...

批量将Excel中的第二列内容从拼音转换为汉字

要批量将Excel中的第二列内容从拼音转换为汉字&#xff0c;您可以使用Python的openpyxl库来实现。下面是一个示例代码&#xff0c;演示如何读取Excel文件并将第二列内容进行拼音转汉字&#xff1a; from openpyxl import load_workbook from xpinyin import Pinyin # 打开Exce…...

消息推送:精准推送,提升运营效果,增添平台活力

对于app开发者而言&#xff0c;没有什么途径比消息推送更能直接、即时地触及目标用户群体了。消息推送与我们的日常生活息息相关&#xff0c;各种APP的状态和通知都通过消息推送来告知用户&#xff0c;引起用户的注意&#xff0c;吸引用户点开app。总而言之&#xff0c;推送服务…...

[保研/考研机试] KY43 全排列 北京大学复试上机题 C++实现

题目链接&#xff1a; 全排列https://www.nowcoder.com/share/jump/437195121692001512368 描述 给定一个由不同的小写字母组成的字符串&#xff0c;输出这个字符串的所有全排列。 我们假设对于小写字母有a < b < ... < y < z&#xff0c;而且给定的字符串中的字…...

Java将时间戳转化为特定时区的日期字符串

先上代码&#xff1a; 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/ 题目描述&#xff1a; 给定一个包含非负整数的数组 nums &#xff0c;返回其中可以组成三角形三条边的三元组个数。 解题思路&#xff1a; 本题是一个关于三角形是否能成立…...

通过 kk 创建 k8s 集群和 kubesphere

官方文档&#xff1a;多节点安装 确保从正确的区域下载 KubeKey export KKZONEcn下载 KubeKey curl -sfL https://get-kk.kubesphere.io | VERSIONv3.0.7 sh -为 kk 添加可执行权限&#xff1a; chmod x kk创建 config 文件 KubeSphere 版本&#xff1a;v3.3 支持的 Kuber…...

感觉和身边其他人有差距怎么办?

虽然清楚知识需要靠时间沉淀&#xff0c;但在看到自己做不出来的题别人会做&#xff0c;自己写不出的代码别人会写时还是会感到焦虑怎么办&#xff1f; 你是否也因为自身跟周围人的差距而产生过迷茫&#xff0c;这份迷茫如今是被你克服了还是仍旧让你感到困扰&#xff1f; 下…...

【C语言基础】宏定义的用法详解

&#x1f4e2;&#xff1a;如果你也对机器人、人工智能感兴趣&#xff0c;看来我们志同道合✨ &#x1f4e2;&#xff1a;不妨浏览一下我的博客主页【https://blog.csdn.net/weixin_51244852】 &#x1f4e2;&#xff1a;文章若有幸对你有帮助&#xff0c;可点赞 &#x1f44d;…...

微服务系列文章之 SpringBoot 最佳实践

Spring Boot 是一种广泛使用且非常流行的企业级高性能框架。 以下是一些最佳实践和一些技巧&#xff0c;我们可以使用它们来改进 Spring Boot 应用程序并使其更加高效。 Spring Boot 的四大核心 1、自动配置 针对很多Spring应用程序和常见的应用功能&#xff0c;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用于启动一个异步任务&#xff0c;并返回一个std::future对象&#xff1b;std::future对象里含有异步任务线程入口函数的结果&#xff1b; 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", …...

【数据结构】 单链表面试题讲解

文章目录 引言反转单链表题目描述示例&#xff1a;题解思路代码实现&#xff1a; 移除链表元素题目描述&#xff1a;示例思路解析&#xff1a; 链表的中间结点题目描述&#xff1a;示例&#xff1a;思路解析代码实现如下&#xff1a; 链表中倒数第k个结点题目描述示例思路解析&…...

C++ string类的模拟实现

模拟实现string类不是为了造一个更好的轮子&#xff0c;而是更加理解string类&#xff0c;从而来掌握string类的使用 string类的接口设计繁多&#xff0c;故而不会全部涵盖到&#xff0c;但是核心的会模拟实现 库中string类是封装在std的命名空间中的&#xff0c;所以在模拟…...

Qt实现简单的漫游器

文章目录 Qt的OpenGL窗口GLSL的实现摄像机类的实现简单的漫游器 Qt的OpenGL窗口 Qt主要是使用QOpenGLWidget来实现opengl的功能。  QOpenGLWidget 提供了三个便捷的虚函数&#xff0c;可以重载&#xff0c;用来重新实现典型的OpenGL任务&#xff1a; paintGL&#xff1a;渲染…...

【c语言】文件操作

朋友们&#xff0c;大家好&#xff0c;今天分享给大家的是文件操作的相关知识&#xff0c;跟着我一起学习吧&#xff01;&#xff01; &#x1f388;什么是文件 磁盘上的文件是文件。 但是在程序设计中&#xff0c;我们一般谈的文件有两种&#xff1a;程序文件、数据文件 程序文…...

【Unity】坐标转换经纬度方法(应用篇)

【Unity】坐标转换经纬度方法&#xff08;应用篇&#xff09; 解决地图中经纬度坐标转换与unity坐标互转的问题。使用线性变换的方法&#xff0c;理论上可以解决小范围内所以坐标转换的问题。 之前有写过[Unity]坐标转换经纬度方法&#xff08;原理篇),在实际使用中&#xff0c…...

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: {/…...

HTML 语义化

目录 HTML 语义化HTML5 新特性HTML 语义化的好处语义化标签的使用场景最佳实践 HTML 语义化 HTML5 新特性 标准答案&#xff1a; 语义化标签&#xff1a; <header>&#xff1a;页头<nav>&#xff1a;导航<main>&#xff1a;主要内容<article>&#x…...

Lombok 的 @Data 注解失效,未生成 getter/setter 方法引发的HTTP 406 错误

HTTP 状态码 406 (Not Acceptable) 和 500 (Internal Server Error) 是两类完全不同的错误&#xff0c;它们的含义、原因和解决方法都有显著区别。以下是详细对比&#xff1a; 1. HTTP 406 (Not Acceptable) 含义&#xff1a; 客户端请求的内容类型与服务器支持的内容类型不匹…...

Prompt Tuning、P-Tuning、Prefix Tuning的区别

一、Prompt Tuning、P-Tuning、Prefix Tuning的区别 1. Prompt Tuning(提示调优) 核心思想:固定预训练模型参数,仅学习额外的连续提示向量(通常是嵌入层的一部分)。实现方式:在输入文本前添加可训练的连续向量(软提示),模型只更新这些提示参数。优势:参数量少(仅提…...

DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径

目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...

Golang dig框架与GraphQL的完美结合

将 Go 的 Dig 依赖注入框架与 GraphQL 结合使用&#xff0c;可以显著提升应用程序的可维护性、可测试性以及灵活性。 Dig 是一个强大的依赖注入容器&#xff0c;能够帮助开发者更好地管理复杂的依赖关系&#xff0c;而 GraphQL 则是一种用于 API 的查询语言&#xff0c;能够提…...

定时器任务——若依源码分析

分析util包下面的工具类schedule utils&#xff1a; ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类&#xff0c;封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz&#xff0c;先构建任务的 JobD…...

pikachu靶场通关笔记22-1 SQL注入05-1-insert注入(报错法)

目录 一、SQL注入 二、insert注入 三、报错型注入 四、updatexml函数 五、源码审计 六、insert渗透实战 1、渗透准备 2、获取数据库名database 3、获取表名table 4、获取列名column 5、获取字段 本系列为通过《pikachu靶场通关笔记》的SQL注入关卡(共10关&#xff0…...

Java多线程实现之Thread类深度解析

Java多线程实现之Thread类深度解析 一、多线程基础概念1.1 什么是线程1.2 多线程的优势1.3 Java多线程模型 二、Thread类的基本结构与构造函数2.1 Thread类的继承关系2.2 构造函数 三、创建和启动线程3.1 继承Thread类创建线程3.2 实现Runnable接口创建线程 四、Thread类的核心…...

Spring Cloud Gateway 中自定义验证码接口返回 404 的排查与解决

Spring Cloud Gateway 中自定义验证码接口返回 404 的排查与解决 问题背景 在一个基于 Spring Cloud Gateway WebFlux 构建的微服务项目中&#xff0c;新增了一个本地验证码接口 /code&#xff0c;使用函数式路由&#xff08;RouterFunction&#xff09;和 Hutool 的 Circle…...

【数据分析】R版IntelliGenes用于生物标志物发现的可解释机器学习

禁止商业或二改转载&#xff0c;仅供自学使用&#xff0c;侵权必究&#xff0c;如需截取部分内容请后台联系作者! 文章目录 介绍流程步骤1. 输入数据2. 特征选择3. 模型训练4. I-Genes 评分计算5. 输出结果 IntelliGenesR 安装包1. 特征选择2. 模型训练和评估3. I-Genes 评分计…...