ruby - Mongoid returns inconsistent doc id after multiple upserts of the same document -


i'm using mongoid gem in ruby. each time upsert, save or insert same unique document in collection, ruby instance shows different id. example, have script so:

class user   include mongoid::document   field :email, type: string   field :name, type: string   index({ email: 1}, { unique: true })   create_indexes end  u=user.new(email: 'test@testers.edu', name: "mr. testy") u.upsert puts u.to_json 

the first time run against empty or non-existent collection, output

{"_id":"52097dee5feea8384a000001","email":"test@testers.edu","name":"mr. testy"} 

if run again, this:

{"_id":"52097e805feea8575a000001","email":"test@testers.edu","name":"mr. testy"} 

but document in mongodb still shows first id (52097dee5feea8384a000001), know operating on same record. if follow upsert find_by operation, right id consistently, feels inefficient have run upsert followed query.

am doing wrong? i'm concerned getting wrong id in operation is, say, updating profile repeatedly.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -