当前位置:网站首页>Use of mongodb
Use of mongodb
2022-06-13 05:15:00 【strive_ one】
Get the database currently in use :
db.getName()
Check the existing database ( Show all databases ):
show databases
# perhaps
show dbs
Select database
use Database name
Delete database
# Select the database first
use Database name
# Then delete the database
db.dropDatabase()
Check the database status
db.stats()
View database related help information
db.help()
View the existing collections in the database
# You should enter the database before viewing the collection : use database
show tables
# perhaps
show collections
Set creation
- Be careful : If use A nonexistent database , You can still create collections in it
use database
db.createCollection(" Collection name ")
# View set
show collections
Delete of collection
db. Collection name .drop()
- Be careful : If you delete a collection that does not exist , Then return to false
Write data
The name of the collection :
- It cannot be an empty string (" ")
- Can not contain \0 character ( Null character )
- Out of commission system. The prefix of ( System reservation )
- It is not recommended to include reserved words ”$”
- use . Split subsets of different namespaces ( Such as :blog.users, blog.posts)
Normal add data
use database
db.createCollection(" Collection name ")
# Insert a piece of data
db. Collection name .insert({
key1:value1, key2:value2})
# Insert multiple data
db. Collection name .insert([{
key1:value1, key2:value2},{
key1:value1, key2:value2}])
db. Collection name .find()
- explain : After the record is successfully inserted ,monogdb One will be added for each document by default _id Field , And in the same set _id Is the only one.
- The _id The content value of the field yes mongodb It's the result of its own algorithm , The _id The corresponding value information is in ” The only global ”
It's equivalent to us mysql The primary key in the table id, Is the only one. . - advantage :mongo We need to upgrade our data 、 It's easier to migrate
Add more for data objects
db. Collection name .insert({
key1:value1, key2:[value1,value2]})
db. Collection name .insert({
key1:value1, key2:{
value1,value2}})
Save the data
db. Collection name .save({
key1:value1, key2:value2})
- characteristic :_id Add if data does not exist , Modify if data exists .
Data query
db. Data sheet .find()
边栏推荐
- Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
- C language learning log 10.19
- 基于 Docker Compose 搭建 Nacos 2(使用 MySQL 进行持久化)
- Detailed explanation of R language sparse matrix
- Brick story
- Introduction to R language 4--- R language process control
- Shell instance
- 2021tami/ image processing: exploiting deep generative priority for versatile image restoration and manipulation
- Nonstandard compiler attribute extension
- File descriptorfile description
猜你喜欢

Reductive elimination

Article 29: assuming that the mobile operation does not exist, is expensive, and is not used

C language learning log 1.22

What is the saturate operation in opencv

Understanding inode

BM1Z002FJ-EVK-001开机测评

redis

Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution论文浅析

ZABBIX proxy, sender (without agent monitoring), performance optimization

Kaggle time series tutorial
随机推荐
The problem of flex layout adaptive failure
Simple SR: best buddy Gans for highly detailed image super resolution
Chapter 17 free space management
metaRTC4.0集成ffmpeg编译
List collection concurrent modification exception
System performance monitoring system
mongo
Case - random numbers without repetition (HashSet and TreeSet)
Course outline of market drawing 1- basic knowledge
Pyqt5 controls qpixmap, qlineedit qsplitter, qcombobox
Chapter 14 introduction: memory operation API
QT interface rendering style
C language learning log 1.16
Configuration used by automatic teaching evaluation script
OpenCV中的saturate操作(饱和操作)究竟是怎么回事
Brick story
Case - the ArrayList collection stores student objects and traverses them in three ways
Shell built-in string substitution
[thread / multithread] execution sequence of threads
C language learning log 1.19