13. Exercises
1. Find all scores less than 65.
2. Find the lowest quiz score. Find the highest quiz score.
3. Write a query to find all digg stories where the view
count is greater than 1000.
4. Query for all digg stories whose media type is either
'news' or 'images' and where the topic name is
'Comedy’.
5. Find all digg stories where the topic name is
'Television' or the media type is 'videos'. Skip the first 5
results, and limit the result set to 10.
15. Exercises
1. Set the proper 'grade' attribute for all scores. For
example, users with scores greater than 90 get an 'A.'
Set the grade to ‘B’ for scores falling between 80 and
90.
2. You're being nice, so you decide to add 10 points to
every score on every “final” exam whose score is
lower than 60. How do you do this update?
use WebNote
db.Notes.save({Title: 'Test'});
db.Notes.update({Title: 'Test'}, {'$set': {Categories: []}});
db.Notes.update({Title: 'Test'}, {'$push': {Categories: { Color: 'Red' }}});
Update Operators: $set, $unset, $inc, $push, $pushAll, $pull, $pullAll, $pop, $addToSet
$push
{ $push : { field : value } }
appends value to field
$set
{ $set : { field : value } }
sets field to value.
use WebNote
db.dropDatabase();
db.Notes.drop();
db.Notes.remove();
cd dump_training
mongorestore -d training -c scores scores.bson
cd dump_digg
mongorestore -d digg -c stories stories.bson
use digg
db.stories.findOne();
db.runCommand({listDatabases: 1})
db.getCollectionNames();
Update Operators: $set, $unset, $inc, $push, $pushAll, $pull, $pullAll, $pop, $addToSet
$push
{ $push : { field : value } }
appends value to field
$set
{ $set : { field : value } }
sets field to value.