【MongoDB】MongoDB之七大实现技巧
技巧一、使用正确的类型 用正确的类型存放数据大有裨益。数据类型影响数据的查询方式、数据存放顺序和以及占用多少空间。 数字:做为数字使用的字段就用数字存储。也就是做计算或按照大小排序的字段数据库会自动转换溢出的(比如由于$inc操作导致的溢出) 32
技巧一、使用正确的类型
用正确的类型存放数据大有裨益。数据类型影响数据的查询方式、数据存放顺序和以及占用多少空间。数字:做为数字使用的字段就用数字存储。也就是做计算或按照大小排序的字段 数据库会自动转换溢出的(比如由于$inc操作导致的溢出) 32位浮点数,将其变为64位整数。
日期:一班的用yyy-mm-dd形式的字符串就可以,如果date类型就会总会匹配到毫秒级别
objectId就要作为objectId存储,千万不要存成字符串。这点非常重要,原因是方便查询 二是objectd中含有用的信息,绝大多数驱动都是从有方法中获得文档的创建日期。 第三objectId表示要多占两陪的磁盘空间。
技巧二、用简单唯一的id替代_id
要是数据库没用唯一的字段,那么就用默认的objetId来做_id。但是若是数据本身就有唯一的字段,并且不需要objectId的功能,那么就用自己唯一的之覆盖默认的id就好了。技巧三、不要用文档做_id
除了不可避免的情况(mapreduce的输出),通常都不应该将文档作为_id。问题在于索引一个文档中的字段和索引文档完全不一样。如果没有每次查询每个子文档的计划,最后会有多个索引。技巧四、不要用数据库引用
数据库引用一般形式是:{$id:主键,$ref:collectionName}(也可以有可选的$db字段,表示数据库)。若被引用的文档集合是确定的,不妨只用_id引用,这样就同时比用Id和集合名要节省空间。 如果知道要引用的集合,数据库引用就显得浪费空间。技巧五、不要用GridFS处理小的二进制数据
GridFS需要查询两次,一次获取文件的元信息,另一次获取内容,所以如果用GridFS存储小文件,会使应用查询次数加倍。从根本上说,GridFS是用来将大的二进制对象切成小片存在数据库中。技巧六、处理“无缝”故障切换
假设发送给服务器一个请求,得到了网络错误,这时驱动有很多选择。若驱动知道有另一台服务器是否自动对其发送请求?要是驱动发送原请求后发生网络故障,或者在服务端响应时候发送故障怎么办?数据库可能已经处理了请求,就不必再次发送。技巧七、处理复制组失效以及故障恢复
可能出现的情况: 应用抛出异常“not master”异常可能原因:1 . 复制组正在进行故障恢复 2, 网络状况不好,无法链接诶主节点。3.应用链接节点有问题,无法降级为只读节点。
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



BitgetLaunchpool is a dynamic platform designed for all cryptocurrency enthusiasts. BitgetLaunchpool stands out with its unique offering. Here, you can stake your tokens to unlock more rewards, including airdrops, high returns, and a generous prize pool exclusive to early participants. What is BitgetLaunchpool? BitgetLaunchpool is a cryptocurrency platform where tokens can be staked and earned with user-friendly terms and conditions. By investing BGB or other tokens in Launchpool, users have the opportunity to receive free airdrops, earnings and participate in generous bonus pools. The income from pledged assets is calculated within T+1 hours, and the rewards are based on

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

Soland's feeding-level lubbing tutorial: 0 cost, no routines, no feedback! Recently, hair removal has once again become a topic of discussion among many friends in the currency circle. Of course, this time everyone is generally disappointed or even angry. The reason is for no other reason. First, there was the tug-of-war of Layerzero’s witch screening batch screening, and then the PUA king ZKsync’s Airdrops have caused many people to complain that they were severely criticized, and some even spent tens of thousands of dollars in gas and interaction costs, and the final benefit was less than one-tenth, not counting the time spent and other costs. The two "King of Heaven" level projects have made many people want to quit the terry circle. In fact, we think it is not necessary here, because there are still many opportunities in the encrypted track. Regardless of the scale, project parties have a need to promote it.

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

Currency Contract: A double-edged sword with high risk and high returns. How to increase the probability of profit? Many veterans in the currency circle have been attracted by the huge potential of contract trading, which can not only bring generous returns but also lead to huge losses. Contract trading is essentially a derivative of digital currency, and its high risk and high returns have attracted much attention. So, how to increase the probability of profit in currency circle contract trading? This requires some key skills. This article will explore in-depth how to reduce risks and improve profitability. Contract profit strategy in the currency circle: In the volatile cryptocurrency market, if you want to achieve stable profits in contract trading, you need to formulate a comprehensive strategy and strictly implement it: Risk management first: setting a stop loss point is the key. Set the stop loss price in advance to control potential losses and avoid single transactions
