Skip to content

Instantly share code, notes, and snippets.

@TomK32
Created February 3, 2010 08:51
Show Gist options
  • Save TomK32/293486 to your computer and use it in GitHub Desktop.
Save TomK32/293486 to your computer and use it in GitHub Desktop.
trash_file = {
file_name: 'gorge_bush.jpg',
user: 'Anonymous',
tags: ['george', 'bush', 'shoe'],
comments: [{_id: new ObjectId(), user: 'Tom', comment: 'Yeah!'}, { _id: new ObjectId(), user: 'oib', comment: 'Hit him!'}],
created_at: new Date(),
points: 0,
delete_at: null,
}
use ourtrash
db.files.insert(trash_file);
trash_file_id = ObjectId('4b68697892c3ae207087b478')
db.files.find();
comment = {
_id: new ObjectId(),
user:"oib",
comment:"super",
website:"http://www.metalab.at",
}
user = {
_id: new ObjectId(),
user_name:'',
user_pass:'',
tags: ['smart', 'sexy'],
}
// http://www.mongodb.org/display/DOCS/Updating?focusedCommentId=4161671#Updating-%24push
db.files.update({_id: trash_file_id}, {$push: {comments: comment}})
// show the updated document
db.files.find({_id: trash_file_id })
db.files.update({_id: trash_file_id}, { $inc:{points:1} })
db.files.update({_id: trash_file_id}, { $inc:{delete_at: new Date() } })
db.files.find({'comments.user': 'oib'})
db.files.find({'comments.website': {$exists: true}})
db.files.find({tags: 'shoe'})
db.files.remove({delete_at: {$lt: new Date()}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment