Note that there are some explanatory texts on larger screens.

plurals
  1. POResolving and Fixing MongoDB / Mongoid ID issues
    primarykey
    data
    text
    <p>This is related to another StackOverflow question from a year ago. But, a bit different. </p> <p>This is in Ruby/Mongoid: 2.2.6.</p> <p>When I got going with MongoDB, it looks like we stored the ID of an MongoDb document incorrectly, because a simple find on an ID is not working, yet it's returning the document when we run a where query on other attributes. </p> <p>I've tried "resetting" the id field by using the object returned from the where and setting the "id" and the "_id" to a BSON::ObjectId version of the stored string. This did not work, as the then record is still not queryable by this field. </p> <p>Any other suggestions before I just completely wipe the disk (losing months of production data) and starting over? </p> <p>Edit: An example of a document that is retuned in the loop that is not retrievable. </p> <pre><code>{"_id"=&gt;"4f47267193546d160b0171a2", "attribute_tags"=&gt;[{"tag"=&gt;"website"}, {"tag"=&gt;"twitter"}, {"tag"=&gt;"website"}, {"tag"=&gt;"twitter"}], "contact_info"=&gt;{"facebook"=&gt;[], "success"=&gt;true, "created_at"=&gt;2012-02-24 05:58:06 UTC, "tags"=&gt;[], "twitter"=&gt;[], "email"=&gt;[], "phone"=&gt;[], "linkedin"=&gt;[], "google_plus"=&gt;[], "youtube"=&gt;[], "contact_form"=&gt;false}, "created_at"=&gt;2012-02-24 05:56:01 UTC, "data"=&gt;{"twitter_followers_count"=&gt;112, "twitter_is_translator"=&gt;112, "twitter_protected"=&gt;false, "twitter_url"=&gt;"http://www.bettyunderground.com", "twitter_verified"=&gt;false, "twitter_statuses_count"=&gt;2040, "twitter_listed_count"=&gt;14, "twitter_geo_enabled"=&gt;true, "twitter_friends_count"=&gt;124, "twitter_created_at"=&gt;"Fri Jul 17 21:41:00 +0000 2009", "twitter_contributors_enabled"=&gt;false, "enriched_at"=&gt;2012-02-24 05:58:09 UTC}, "demographics"=&gt;{}, "description"=&gt;"The trials and tribulations of a polemicist", "directory_ids"=&gt;[], "forums"=&gt;[], "found_at_url"=&gt;"http://www.bettyunderground.com", "geographics"=&gt;{"language"=&gt;"en", "location"=&gt;"San Francisco, CA"}, "hashtags"=&gt;{"tag"=&gt;{"website"=&gt;true, "twitter"=&gt;true}, "reachable_via"=&gt;{"twitter"=&gt;true}}, "host_names"=&gt;[], "ignore_project_ids"=&gt;[], "keyword_scores"=&gt;{"return policy"=&gt;0.0}, "keywords"=&gt;["return policy"], "last_contact_info_update"=&gt;2012-02-24 05:58:09 UTC, "name"=&gt;"Betty Underground", "new_profiles"=&gt;[{"service"=&gt;"twitter", "user_id"=&gt;"BettyUndergrnd", "score"=&gt;1.0}, {"service"=&gt;"twitter", "username"=&gt;"BettyUndergrnd", "score"=&gt;1.0}], "presence_score"=&gt;0, "profile_url"=&gt;"http://a2.twimg.com/profile_images/1459407098/image_normal.jpg", "profiles_retrieved"=&gt;true, "references"=&gt;[], "share_counts"=&gt;{}, "tags"=&gt;["website", "twitter"], "twitter"=&gt;"BettyUndergrnd", "updated_at"=&gt;2012-03-17 10:08:09 UTC, "wordsmaster_ids"=&gt;[], "reachable_via"=&gt;[], "read_project_ids"=&gt;[]} </code></pre> <p>It doesn't have a ObjectId for the ID field. Not sure how it got busted this way, but that's the way it is. </p> <p>The code I'm using to modify it is:</p> <pre><code>#if d is the document old_id = d._id d["_id"] = BSON::ObjectId(old_id) d.save </code></pre> <p>I have placed a gist of doing this from my console. You can see exactly what I'm doing. </p> <p>Any thoughts would be appreciated. </p> <p><a href="https://gist.github.com/2087011" rel="nofollow">https://gist.github.com/2087011</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload