当前位置:网站首页>Difference between redis and mongodb (useful for interview)
Difference between redis and mongodb (useful for interview)
2022-07-25 09:19:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
What is used in the project MongoDB, But why? In fact, there was not much consideration when selecting models , I just think the amount of data is relatively large , So using MongoDB.
Recently, I remembered why I used MongoDB, Just check , Summary summary summary :
I used it before redis, It was used to store some thermal data , Not much , But the operation is very frequent . Now the project uses MongoDB, At present, it is a million level data , There will be tens of millions in the future 、 Billion level .
Just Redis and MongoDB Come on , It is generally called Redis cache 、MongoDB database . This is also reasonable and justified ,
Redis Mainly store data in memory , Its “ cache ” The nature of is far greater than its “ data storage “ The nature of , The addition, deletion, modification and query of data are just as simple as variable operation ;
MongoDB But one. “ Store the data ” The system of , Adding, deleting, modifying and querying can add many conditions , It's like SQL As flexible as a database , This is very useful in the interview .
Mongodb And Redis Application index comparison
MongoDB and Redis All are NoSQL, Using structured data storage . Both of them are used in the scene , There is a certain difference , This is mainly due to In the process of memory mapping , Persistence is handled differently .MongoDB Cluster deployment is recommended , Think more about the cluster solution ,Redis More emphasis on process sequential writing , Although it supports clustering , It is also limited to the main - Slave mode .
MongoDB Syntax and existing relational databases SQL Grammatical comparison
MongoDB grammar MySql grammar
db.test.find({'name':'foobar'}) <==> select * from test where name='foobar'
db.test.find() <==> select *from test
db.test.find({'ID':10}).count() <==> select count(*) from test where ID=10
db.test.find().skip(10).limit(20) <==> select * from test limit 10,20
db.test.find({'ID':{$in:[25,35,45]}}) <==> select * from test where ID in (25,35,45)
db.test.find().sort({'ID':-1}) <==> select * from test order by IDdesc
db.test.distinct('name',{'ID':{$lt:20}}) <==> select distinct(name) from testwhere ID<20
db.test.group({key:{'name':true},cond:{'name':'foo'},reduce:function(obj,prev){prev.msum+=obj.marks;},initial:{msum:0}}) <==> select name,sum(marks) from testgroup by name
db.test.find('this.ID<20',{name:1}) <==> select name from test whereID<20
db.test.insert({'name':'foobar','age':25}) <==> insertinto test ('name','age') values('foobar',25)
db.test.remove({}) <==> delete * from test
db.test.remove({'age':20}) <==> delete test where age=20
db.test.remove({'age':{$lt:20}}) <==> delete test where age<20
db.test.remove({'age':{$lte:20}}) <==> delete test where age<=20
db.test.remove({'age':{$gt:20}}) <==> delete test where age>20
db.test.remove({'age':{$gte:20}}) <==> delete test where age>=20
db.test.remove({'age':{$ne:20}}) <==> delete test where age!=20
db.test.update({'name':'foobar'},{$set:{'age':36}})<==> update test set age=36 where name='foobar'
db.test.update({'name':'foobar'},{$inc:{'age':3}})<==> update test set age=age+3 where name='foobar'
Fuzzy query :$regex
db.test.find({"name":{$regex:"aaa"}})
Group number filtering
db.getCollection('id_mapper').aggregate([{$group:{ _id :"$contract_id",count:{$sum:1}}},{$match:{count:{$gt:1}}}])
Determine whether it is null
db.getCollection('id_mapper').find({"sinocardid":{$in:[null]}})Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/111446.html Link to the original text :https://javaforall.cn
边栏推荐
- Bi business interview with data center and business intelligence (I): preparation for Industry and business research
- [machine learning] Finally, the important steps of machine learning modeling have been clarified
- nacos2.1.0集群搭建
- activemq--死信队列
- Opencv realizes simple face tracking
- The annualization of financial products is 4%. How much profit can you get from buying 10000 yuan a month?
- Redis operation uses cursor instead of keys
- office文件对应的Content-Type类型
- 酷炫canvas动画冲击波js特效
- Nacos搭建配置中心出现client error: invalid param. endpoint is blank
猜你喜欢

activemq--可持久化机制之JDBC的journal

LabVIEW experiment - temperature detection system (experimental learning version)

360度拖拽全景图插件tpanorama.js

ActiveMQ -- message retry mechanism

分享一个避免递归的部门设计方法

Illustration leetcode - 919. Complete binary tree inserter (difficulty: medium)
[learn rust together] a preliminary understanding of rust package management tool cargo

Wechat applet obtains the data of ---- onenet and controls the on-board LED of STM32

整理 华为AP-3010DN_V2配置创建wifi

【Nacos】NacosClient在服务注册时做了什么
随机推荐
mysql中的数据结果排名
神经网络学习(1)前言介绍
[NPM] the "NPM" item cannot be recognized as the name of cmdlets, functions, script files or runnable programs. Please check the spelling of the name. If the path is included, make sure the path is co
ActiveMQ -- message retry mechanism
Guangzhou has carried out in-depth "100 day action" to check the safety of self built commercial houses, and more than 2 million houses have been checked in two months
Dark horse programmer JDBC
How does Flink SQL persist?
【线程知识点】-- 自旋锁
Illustration leetcode - 1184. Distance between bus stops (difficulty: simple)
Silicon Valley class lesson 11 - official account news and wechat authorization
table表格展开内部行切换效果
Neural network learning (1) Introduction
『每日一问』ReentrantLock加锁解锁
Ten thousand words long, one word thoroughly! Finally, someone has made business intelligence (BI) clear
The garbage classification data set used in the excellent Yolo target detection training is shared - about 3000 labeled
Nacos搭建配置中心出现client error: invalid param. endpoint is blank
What version of Oracle10g single instance database is better to upgrade to? Ask for suggestions
[stl]list Simulation Implementation
Leetcode组合总和+剪枝
JDBC快速入门