Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic operating commands of mongodb

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

= = basic operation command of mongodb =

DDL operation =

Create the schema: use Schema; create an object in Schema to db.createCollection ("CollectionName"). Equivalent to create database DBName

Create a collection: db.createCollection ("test"); equivalent to the creation table create table TableName () in DBMS

Showcase architecture: show dbs; is equivalent to show databases in mysql

Show the number of collections: show collections; show tables

Delete the current architecture: use Schema; db.dropDatabase (); drop database DBName

Modify the collection name: db.CollectionName.renameCollection ("NewName"); similar to alter table oldTable rename to NewTable in mysql

Delete collection: db.collections.drop (); similar to drop table tableName in mysql

View the current DB:db

User-related actions =

Add user: db.addUser ("UserName", "PWD")

Verify that the user has been added successfully: db.auth ("UserName", "PWD")

Delete user: db.removUsers ("testUser")

Permission related:

Http://blog.itpub.net/22664653/viewspace-715617/

DML operation =

Query collection: db.CollectionName.find ({}); equivalent to select * from TableName

Equality condition query: db.CollectionName.find ({key01:value01}); equivalent to select * from TableName where key01=value01

Different values of the query field (deduplicated): db.CollectionName.distinct ("Key") is similar to select distinct (key) from table

Fuzzy query: db.collections.find ({key:/ang/}); select * from tableName where key like'% ang%'

: db.collections.find ({key:/ ^ ang /}); select * from tableName where key like 'ang%'

: db.collections.find ({key:/g$/}); select * from tableName where key like'% ang'

Query the specified list: db.collections.find ({}, {key01:false,key02:true,key03:true}); select key02,key03 from tableName

Range lookup: db.collections.find ({key01: {$gt:20}}); select * from tableName where key01 > 20

: db.collections.find ({key01: {$lge:20}}); select * from tableName where key01 > = 20

: db.collections.find ({key01: {$lt:20}}); select * from tableName where key01 < 20

: db.collections.find () {key01: {$lte:20}}; select * from tableName where key01 = 24 and key01

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report