Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB usage Summary Series 2

Shulou Source: shulou.com Published: 2022-06-01 09:14:17 10月04日 Update

Because I am accustomed to using relational database, I feel that the flexibility of SQL statement to operate on data is needless to say and easy to understand and grasp, but after starting to use MongoDB, it is always awkward to operate on some data on the client command line, always prompting syntax errors. Although tools such as RockMongo or MongoVUE provide a lot of convenience, some operations still require command line operations. So make a general summary of the data manipulation commands on the command line:

1. View command prompts

Db.help ()

Db.collname.help ()

Db.collname.find () .help ()

Re.help ()

two。 Toggle creation of database

Use dbname

3. Query all databases

Show dbs

4. Delete the database currently in use

Db.dropDataBase ()

5. Create a collection (table)

Db.createCollection ("name", {size:1,capped:5,max:100})

6. Query

Db.table.find () is equivalent to: select * from table

Db.table.distinct ("name") is equivalent to: select distinct name from table

Db.table.find ({"age": 22}) is equivalent to: select * from table where age=22

Db.table.find ({"age": {$gte:22}}) is equivalent to select * from table where age > = 22

Db.table.find ({"age": {$lt:22}}) is equivalent to select * from table where age10 and age

Tags: Data commands databases prompts queries awkwardness no clients clients tools flexibility statements syntax or errors switching Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information MySQL Microsoft Shulou Technology