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

Mongodb simple operation

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

1. After performing mongod.exe server startup, you can follow the parameters to describe the database and logs that are started.

Eg:

Mongod.exe-bind_ip 127.0.0.1-logpath "F:\ data\ dbConf\ mongodb.log"-- logappend-- dbpath "F:\ data\ db"-- port 19901-- serviceName "mongodb1"-- serviceDisplayName "mongodbAll"-- install

2. Perform mongo.exe client connection

View all databases: show dbs

Syntax format for creating a database: use DATABASE_NAME

Delete the current database: db.dropDatabase ()

Switch to database: use DATABASE_NAME

Delete collection: db.collection.drop ()

MongoDB uses the insert () or save () methods to insert documents into the collection:

Db.COLLECTION_NAME.insert (document)

MongoDB uses the update () and save () methods to update documents in the collection:

The update () method is used to update existing documents. The syntax format is as follows:

Db.collection.update (

, / / query: the query condition of update, which is similar to that after where in the sql update query.

, / / update: the object of update and some updated operators (such as $, $inc...), etc., can also be understood as the following set in the sql update query

{

Upsert: / / upsert: optional, this parameter means that if there is no record of update, whether to insert objNew,true is insert, default is false, do not insert.

Multi: / / multi: optional. Mongodb defaults to false. Only the first record found is updated. If this parameter is true, all records found by condition will be updated.

WriteConcern: / / writeConcern: optional, the level at which the exception is thrown.

}

)

The save () method replaces an existing document with an incoming document. The syntax format is as follows:

Db.collection.save (

{

WriteConcern:

}

)

Db.col.update ({'title':'MongoDB tutorial'}, {$set: {'title':'MongoDB'}})

MongoDB deletes a document

Parameter description:

Document: document data.

WriteConcern: optional, the level at which the exception is thrown.

The basic syntax format of the remove () method is as follows:

Db.collection.remove (

)

Remove all data: db.col.remove ({})

The syntax format of MongoDB query data is as follows:

Db.COLLECTION_NAME.find ()

Read data in a readable manner

Db.col.find () .pretty ()

Similar statements in the example RDBMS of the action format

Equals {:} db.col.find ({"by": "Rookie tutorial"}) .pretty () where by = "Rookie tutorial"

Less than {: {$lt:} db.col.find ({"likes": {$lt:50}}) .pretty () where likes

< 50 小于或等于 {:{$lte:}} db.col.find({"likes":{$lte:50}}).pretty() where likes 50 大于或等于 {:{$gte:}} db.col.find({"likes":{$gte:50}}).pretty() where likes >

= 50

Not equal to {: {$ne:} db.col.find ({"likes": {$ne:50}}) .pretty () where likes! = 50

The conditional operators in MongoDB are:

(>) greater than-$gt

(=) greater than or equal to-$gte

(100)

I wrote down the above while typing the website myself.

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