当前位置:网站首页>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
边栏推荐
- Kubedm introduction
- Collection of common algorithm questions in test post interview
- 酷炫canvas动画冲击波js特效
- ActiveMQ -- JDBC Journal of persistent mechanism
- What are the commands used by pl/sql tools to export SQL files?
- Canvas text JS special effect composed of many circles
- The development of art NFT
- [STL]list模拟实现
- ActiveMQ -- message retry mechanism
- Feiling ok1028a core board adapts to rtl8192cu WiFi module
猜你喜欢

【Nacos】NacosClient在服务注册时做了什么

全网最简约的sklearn环境配置教程(百分百成功)

Sort out Huawei ap-3010dn_ V2 configuration create WiFi

Programmers can't SQL? Ashes Engineer: all waiting to be eliminated! This is a must skill!
![[STL]stack&queue模拟实现](/img/92/c040c0e937e2666ee179189c60a3f2.png)
[STL]stack&queue模拟实现

酷炫canvas动画冲击波js特效

『怎么用』装饰者模式

What is steel grating?

Labview--- signal generator
![[NPM] the](/img/ae/efccefae0323a1f6a425523e01d2ac.png)
[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
随机推荐
为什么说DAO是未来的公司形式
Wechat applet obtains the data of ---- onenet and controls the on-board LED of STM32
图解LeetCode——1184. 公交站间的距离(难度:简单)
Activemq-- delayed delivery and scheduled delivery
OpenCV实现简单的人脸追踪
Asp. Net core CMD common instructions
activemq--消息重试机制
Redis sentry, master-slave deployment details
OmniPeek packet capturing tool
[machine learning] Finally, the important steps of machine learning modeling have been clarified
Cool canvas animation shock wave JS special effect
Illustration leetcode - 1184. Distance between bus stops (difficulty: simple)
The hole of scroll view in uniapp
table表格展开内部行切换效果
Leetcode-238. product of arrays other than itself
【Nacos】NacosClient在服务注册时做了什么
mysql中的数据结果排名
『每日一问』简单聊聊JMM/说说对JMM的了解
ActiveMQ -- leveldb of persistence mechanism
『每日一问』volatile干嘛的