Homework 1.1
What would be the output of the below script if you run in mongo shell ?
db.products.find()
What would be the output of the below script if you run in mongo shell ?
db.isMaster().maxBsonObjectSize
16777216
Below is the referenced screen shot
Below is the referenced screen shot
Homework 1.2
Now, import its contents into MongoDB, into a database called "pcat" and a collection called "products". Use the mongoimport utility to do this.When done, run this query in the mongo shell what would be the result ?
Now, import its contents into MongoDB, into a database called "pcat" and a collection called "products". Use the mongoimport utility to do this.When done, run this query in the mongo shell what would be the result ?
Homework 1.3
At this point you should have pcat.products loaded from the previous step. You can confirm this by running in the shell:
At this point you should have pcat.products loaded from the previous step. You can confirm this by running in the shell:
db.products.find()
// or:
db.products.count()
// should print out "11"
Now,
what query would you run to get all the products where brand equals the string ACME”?
db.products.find({brand:"ACME"})
Below is the referenced screen shot
Homework 1.4
How would you print out, in the shell, just that the value in the "name" field, for all the product documents in the collection, without extraneous characters or braces, sorted alphabetically, ascending?
Below is the referenced screen shot
Homework 1.4
How would you print out, in the shell, just that the value in the "name" field, for all the product documents in the collection, without extraneous characters or braces, sorted alphabetically, ascending?
var c = db.products.find({}).sort({name:1}); c.forEach(
function(doc){ print(doc.name) } );
var c = db.products.find({},{name:1,_id:0}).sort({name:1});
while( c.hasNext() ) print( c.next().name);
Below is the referenced screen shot
Below is the referenced screen shot
No comments:
Post a Comment