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

Addition, deletion, modification and search of mongodb

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Added: db.collection_name.insert

Delete: db.collection_name.remove

Update: db.collection_name.update

Query: db.collection_name.find () .pretty ()

Operation example:

1. Create a database

Use test2

two。 Show all current databases

Show dbs

3. The test2 you just created will not be displayed. You need to insert some data into it.

Db.test2.insert ({"name": "I am your uncle"})

two。 Delete database

1. Connect to the database

Use test2

two。 Perform deletion

Db.dropDatabase ()

three。 Create a collection

Use test2

Db.createCollection ("test3")

Show collections

four。 Delete a collection

Use test2

Db.test3.drop ()

five。 New document

Use test2

Db.test3.insert ({title: 'MongoDB tutorial'

Description: 'MongoDB is a Nosql database'

By: 'tutorial'

Url: 'http://www.runoob.com',

Tags: ['mongodb',' database', 'NoSQL']

Likes: 100})

Db.test3.insert ({

Title: 'PHP tutorial'

Description: 'PHP is a powerful server-side scripting language for creating dynamic interactive sites.'

By: 'tutorial'

Url: 'http://www.runoob.com',

Tags: ['php']

Likes: 150})

Db.test3.insert ({

Title: 'TEST tutorial'

Description: 'TEST is a powerful server-side scripting language for creating dynamic interactive sites.'

By: 'tutorial'

Url: 'http://www.runoob.com',

Tags: ['test']

Likes: 200})

Check whether the document has been added successfully:

Db.test3.find () .pretty ()

six。 Update document

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

seven。 Delete document

Db.test3.remove ({"title": "TEST tutorial"})

eight。 Query documents, query data in documents with a likelihood value greater than or equal to 150

MongoDB Enterprise > db.test.find ({likes: {$gte: 150}})

{"_ id": ObjectId ("5dd110022ad82fd1af1a82e0"), "title": "PHP tutorial", "description": "PHP is a powerful server-side scripting language for creating dynamic interactive sites." , "by": "tutorial", "url": "http://www.runoob.com"," tags ": [" php "]," likes ": 150}

{"_ id": ObjectId ("5dd110382ad82fd1af1a82e1"), "title": "TEST tutorial", "description": "TEST is a powerful server-side scripting language for creating dynamic interactive sites." , "by": "tutorial", "url": "http://www.runoob.com"," tags ": [" test "]," likes ": 200}

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

Servers

Wechat

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

12
Report