当前位置:网站首页>Some basic uses of mongodb
Some basic uses of mongodb
2022-06-26 00:13:00 【Daily log of the great demon king】
establish MongoDB Containers
docker run di --name=tianxingwen_mongodb -p 27017:27017 mongo
Remote login
mongo 192.168.53.132
Create database
use spitdb
Add, delete, change and look up the grammar
Inquire about
grammar :
db. Collection name .find()
db.spit.find()
according to id Query a piece of data
db.spit.find({"_id":“1”})
db.spit.findOne({"_id":“1”})
Query the first few data
db.spit.find().limit(3)
newly added
insert data
grammar :
db. Collection name .insert( data );
db.spit.insert({content:“ It's so cold ”,visits:10})
modify
grammar :
db. Collection name .update( Conditions , Revised data )
db.spit.update({_id:“1”},{visits:NumberInt(1000)})
Note that after the above command is executed id by 1 All other fields of the will be deleted automatically
terms of settlement :
db.spit.update({_id:“2”},{$set:{visits:NumberInt(2000)}})
Delete
grammar :
db. Collection name .remove( Conditions )
Delete all
db.spit.remove({})
Delete... According to conditions Delete visits:1000 This data of
db.spit.remove({visits:1000})
Statistics
Statistics of all
db.spit.count()
Statistics according to specified conditions
db.spit.count({userid:“1013”})
Fuzzy query
Inquire about content Field contains java All documents of
db.spit.find({content:/java/})
Inquire about content With java At the beginning
db.spit.find({content:/^java/})
Greater than less than
grammar :
db. Collection name .find({ “field” : { $gt: value }}) // Greater than : field > value db. Collection name .find({ “field” : { $lt: value }}) // Less than : field < value db. Collection name .find({ “field” : { $gte: value }}) // Greater than or equal to : field >= value
db. Collection name .find({ “field” : { $lte: value }}) // Less than or equal to : field <= value
db. Collection name .find({ “field” : { $ne: value }}) // It's not equal to : field != value
Inquire about id>1 The data of
db.spit.find({"_id":{$gt:“1”}})
Inclusion and exclusion
Inquire about userid Field contains 1013,1014 Documents
db.spit.find({userid:{$in:[“1013”,“1014”]}})
Inquire about userid Field does not contain 1013,1014 Documents
db.spit.find({userid:{$nin:[“1013”,“1014”]}})
Conditional connection
Grammar format
$and:[ { },{ },{ } ]
Query collection visits Greater than or equal to 1000 And less than 2000 The article of
db.spit.find({ KaTeX parse error: Expected '}', got 'EOF' at end of input: and:[ {visits:{ gte:1000}} ,{visits:{$lt:2000} }]})
If the relationship between two or more conditions is or , We use Operators , With the front and Use The same way
KaTeX parse error: Expected '}', got 'EOF' at end of input: …*db.spit.find({ or:[ {userid:“1013”} ,{visits:{$lt:2000} }]})
Secondary title
Increase or decrease the value of a column on the basis of the original value , have access to KaTeX parse error: Expected '}', got 'EOF' at end of input: …ate({_id:"2"},{ inc:{visits:NumberInt(1)}} )**
边栏推荐
猜你喜欢

每日刷题记录 (四)

86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)

Efficacy of kiwi fruit enzyme_ Old bear passing by_ Sina blog

How postman tests interfaces that require login

Literature research (III): overview of data-driven building energy consumption prediction models

dhcp复习

How to configure SQL Server 2008 Manager_ Old bear passing by_ Sina blog

10.2.3、Kylin_kylin的使用,维度必选

Redis之内存淘汰机制

EBS R12.2.0升级到R12.2.6
随机推荐
Sword finger offer 48 Longest substring without duplicate characters
How ASA configures port mapping and pat
[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)
Reading notes on how to connect the network - hubs, routers and routers (III)
Number array de duplication in JS
Redis之常见问题
Mysql5.7.31自定义安装详细说明
电路板去板边—V-Cut分板机注意事项
Efficacy of kiwi fruit enzyme_ Old bear passing by_ Sina blog
SMT贴片加工pcba立碑现象的原因和解决方法
farsync 简易测试
10.2.3、Kylin_kylin的使用,维度必选
Using swiper to realize the rotation chart
Redis之内存淘汰机制
MySQL master-slave replication
Literature research (II): quantitative evaluation of building energy efficiency performance based on short-term energy prediction
2021-04-28
Stop eating vitamin C tablets. These six fruits have the highest vitamin C content
深圳台电:联合国的“沟通”之道
About the solution to prompt modulenotfounderror: no module named'pymongo 'when running the scratch project