Mongodb commands: Please use hypothetical collection called “logdata” in answeri
ID: 3752552 • Letter: M
Question
Mongodb commands:Please use hypothetical collection called “logdata” in answering the questions. submit a copy of the command used.
Questions:
List all the data in the collection “logdata”. Count all requests that have a request_status = 400. List all requests from the Android operating system. This information can be found in the field “message”. List all requests that came on Jan 1 2017 after 12:00 hours. List all requests from IP = 192.168.251.152 and order the information by most recent to oldest. Mongodb commands:
Please use hypothetical collection called “logdata” in answering the questions. submit a copy of the command used.
Questions:
List all the data in the collection “logdata”. Count all requests that have a request_status = 400. List all requests from the Android operating system. This information can be found in the field “message”. List all requests that came on Jan 1 2017 after 12:00 hours. List all requests from IP = 192.168.251.152 and order the information by most recent to oldest. Mongodb commands:
Please use hypothetical collection called “logdata” in answering the questions. submit a copy of the command used.
Questions:
List all the data in the collection “logdata”. Count all requests that have a request_status = 400. List all requests from the Android operating system. This information can be found in the field “message”. List all requests that came on Jan 1 2017 after 12:00 hours. List all requests from IP = 192.168.251.152 and order the information by most recent to oldest.
Explanation / Answer
MongoDB is a docment database with the scalability and flexibility. It stores data in flexible JSON liek documents to vary fields vary from documents to documents. It is free and open source, published under the GNU Affero General Public License.
In or question we created a collection named as "logdata".
Firstly login to MongoDB using username and password,
mongo -u <username> -p <password> --authenticationDatabase <dbname>
Now we are login to our MongoDB. If we have a database the select the database to use :
use databaseName
If we dont have database then create a new database and use:
use databasename
Now we can list all collections if any otherwise create new collection.To display all collections,
show collections;
db.getCollectionNames();
If we dont have collection then create a new collection using,
db.createCollection("collection name");
(a) Here we have collection logdata. So listing all data in logdata, syntax will be,
db.collectionName.find()
so our code will be,
db.logdata.find()
(b) Count all requests that have a request_status = 400
db.collection.find().count() will return the count.
Here we have to write,
db.logdata.find( { request_status : {$eq:400} } ).count()
(c) List alll requests from the Android operating system.
Here we have to list all requests having message as Android operating system.
db.logdata.find( { message : { $eq : "Android operating system"} } )
(d) List all requests come on Jan 1 2017 after 12:00 hours
db.logdata.find( {$hour: new Date("2017-01-01T12:00:00Z") } )
(e) List all requests from IP = 192.168.251.152 and order the information by most recent to oldest
db.logdata.find( { IP : { $eq : "192.168.251.152 "} , $orderby : {time: -1 } } )
here sorting is done according to the time value. Record with latest time value will be displayed first.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.