Skip to content

Instantly share code, notes, and snippets.

View jseibert's full-sized avatar

Jeff Seibert jseibert

View GitHub Profile
# Ensure apps are created for the organization atomically by using find_and_modify
result = App.collection.find_and_modify({
:query => {
:bundle_identifier => params[:id].downcase,
:organization_id => current_organization._id },
:update => {
"$set" => {
:bundle_identifier => params[:id].downcase,
:organization_id => current_organization._id } },
:new => true,
# Warm the db by doing a find before the find_and_modify
find_record(
'devices',
{ :did => data[:did], :organization_id => BSON::ObjectId(data[:organization_id]) },
{ :fields => { :_id => 1 } }
)
device = find_and_modify_record(
'devices',
{ :did => data[:did], :organization_id => BSON::ObjectId(data[:organization_id]) },