- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set server status to inactive in a MongoDB collection with server records?
Let us create a collection with documents −
> db.demo707.insertOne( ... { ... id:101, ... "serverInformation": ... [ ... { ... "IP":"192.56.34.3", ... "Status":"Active" ... }, ... { ... "IP":"192.56.36.4", ... "Status":"Inactive" ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5ea6f852551299a9f98c93c8") }
Display all documents from a collection with the help of find() method −
> db.demo707.find();
This will produce the following output −
{ "_id" : ObjectId("5ea6f852551299a9f98c93c8"), "id" : 101, "serverInformation" : [ { "IP" : "192.56.34.3", "Status" : "Active" }, { "IP" : "192.56.36.4", "Status" : "Inactive" } ] }
Following is the query to set active server to inactive status −
>db.demo707.update({"serverInformation.IP":"192.56.34.3"},{$set:{"serverInformation.$.Status":"Inactive"}}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo707.find();
This will produce the following output −
{ "_id" : ObjectId("5ea6f852551299a9f98c93c8"), "id" : 101, "serverInformation" : [ { "IP" : "192.56.34.3", "Status" : "Inactive" }, { "IP" : "192.56.36.4", "Status" : "Inactive" } ] }
- Related Articles
- Get all embedded documents with “isMarried” status in a MongoDB collection
- Select records with ACTIVE status in MySQL set with ENUM
- How can I check the status of MySQL Server?
- MongoDB GroupBy to set status
- How To Set Up Multiple SSL Host With A Single Apache Server
- How to Set-Up Shiny Server on Ubuntu
- Get the maximum mark records from a collection with documents in MongoDB
- MongoDB Convert One record with an array to multiple records in a new collection?
- MongoDB query to retrieve records from a collection named with letters and numbers
- MySQL Server and Server-Startup Programs
- Deleting all records of a collection in MongoDB Shell?
- How to get latest set of data from a MongoDB collection based on the date records?
- How to Configure Nagios Server for Monitoring Apache Server
- Get the maximum mark records from a collection with documents in MongoDB query
- Difference between Web Server and Application Server

Advertisements