Guest User

Untitled

a guest
May 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. require 'rubygems'
  2. require 'mongo'
  3.  
  4. uid, aid = BSON::ObjectID.new, BSON::ObjectID.new
  5. db = Mongo::Connection.new.db('testing')
  6. db.drop_collection('ratings')
  7. db.create_collection('ratings')
  8.  
  9. ratings = db['ratings']
  10. ratings.create_index([[:user_id, Mongo::ASCENDING], [:article_id, Mongo::ASCENDING]], :unique => true)
  11.  
  12. ratings.save({:user_id => uid, :article_id => aid}, :safe => true)
  13. ratings.save({:user_id => uid, :article_id => aid}, :safe => true)
Add Comment
Please, Sign In to add comment