In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The database will be created (create), read (find), updated (update), deleted (remove), and MongoDB will also be used
First, create
Use the insert function to add documents to the collection. For example
Create the database blog and add the document to the collection post (first put the document in the variable of post)
> post= {"title": "My blog post", "context": "Here's my blog post", "date": new Date ()} > use blog switched to db blog > db.post.insert (post); WriteResult ({"nInserted": 1})
Second, read
Use the find method or the findone method to view the documents in the collection, such as
> db.post.find () {"_ id": ObjectId ("54a50253e287e09898eab58b"), "title": "My blog post", "context": "Here's my blog post", "date": ISODate ("2015-01-01T08:15:14.121Z")} > db.post.findOne () {"_ id": ObjectId ("54a50253e287e09898eab58b"), "title": "My blog post" Context: "Here's my blog post", "date": ISODate ("2015-01-01T08:15:14.121Z")} >
III. Update
Reassign the variable post
> use blog switched to db blog > post=db.post.findOne () {"_ id": ObjectId ("54a50253e287e09898eab58b"), "title": "My blog post", "context": "Here's my blog post", "date": ISODate ("2015-01-01T08:15:14.121Z")}
Add an comments document to the variable post
> post.comments = [] []
The update method updates the collection
> db.post.update ({"title": "My blog post"}, post) WriteResult ({"nMatched": 1, "nUpserted": 0, "nModified": 1}) > db.post.findOne () {"id": ObjectId ("54a50253e287e09898eab58b"), "title": "My blog post", "context": "Here's my blog post", "date": ISODate ("2015-01-01T08:15:14.121Z") "comments": []}
IV. Delete
Delete a document with the removed method
> db.post.remove ({"title": "My blog post"}); WriteResult ({"nRemoved": 1}) > db.post.findOne (); null >
The post collection is empty after deletion
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.