Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use securerandom for _id on 1.8.7

  • Loading branch information...
commit 1325c942b2b05f560d988e857a80d9b895044638 1 parent 75028f7
@tmm1 authored
Showing with 11 additions and 3 deletions.
  1. +0 −1  lib/mongo.rb
  2. +11 −2 lib/mongo/collection.rb
View
1  lib/mongo.rb
@@ -2,7 +2,6 @@
require 'ext/em'
require 'ext/fiber18'
require 'ext/emspec'
-require 'uuid'
module Mongo
class Error < Exception; end
View
13 lib/mongo/collection.rb
@@ -1,3 +1,9 @@
+begin
+ require 'securerandom'
+rescue LoadError
+ require 'uuid'
+end
+
module Mongo
class Collection
@@ -38,8 +44,11 @@ def first *args
end
def insert obj
- obj[:_id] ||= UUID.new(:compact).gsub(/^(.{20})(.{8})(.{4})$/){ $1+$3 }
- p [:inserting, obj]
+ obj[:_id] ||= if defined? SecureRandom
+ SecureRandom.hex(12)
+ else
+ UUID.new(:compact).gsub(/^(.{20})(.{8})(.{4})$/){ $1+$3 }
+ end
@client.send 2002, :int, reserved = 0,
:cstring, @ns,
Please sign in to comment.
Something went wrong with that request. Please try again.