当前位置:网站首页>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
边栏推荐
猜你喜欢
![[SCADA case] myscada helps VIB company realize the modernization and upgrading of production line](/img/67/b8c397d78a675014b5e08ceefc88dc.png)
[SCADA case] myscada helps VIB company realize the modernization and upgrading of production line

音乐人的 NFT 指南

LabVIEW experiment - temperature detection system (experimental learning version)

uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec

Nacos搭建配置中心出现client error: invalid param. endpoint is blank

图解LeetCode——919. 完全二叉树插入器(难度:中等)

Sticky.js page scrolling div fixed position plug-in

This ten-year content industry infrastructure company is actually an invisible Web3 pioneer
![[C language] dynamic memory management, flexible array](/img/da/b9455885df0cb6646908e3655d62c5.png)
[C language] dynamic memory management, flexible array

Composition of the interview must ask items
随机推荐
activemq--异步投递
『每日一问』LockSupport怎么实现线程等待、唤醒
activemq--持久化机制之LevelDB
Labview--- signal generator
canvas动态图片头像晃动js特效
The annualization of financial products is 4%. How much profit can you get from buying 10000 yuan a month?
ActiveMQ -- persistent mechanism
为什么说DAO是未来的公司形式
Probe into Druid query timeout configuration → who is the querytimeout of datasource and jdbctemplate effective?
The operation cannot be completed because a folder or file in it is already open in another program
Table table expansion internal row switching effect
Uniapp intercepts route jumps through addinterceptor to control whether the page needs to log in
nacos2.1.0集群搭建
Illustration leetcode - 1184. Distance between bus stops (difficulty: simple)
『每日一问』ReentrantLock加锁解锁
Solve NPM error: cannot find module 'shelljs‘
office文件对应的Content-Type类型
实现简单的RESTful API服务器
Write two channel (stereo) immediately Wav file
How to use pixi.js to make simple Parkour games