Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-261

Use the DBRef convention for references

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Would be nice if Mongoid started using the DBRef convention.

      Benefits:
      This is the approach that 10Gen and MongoDB recommends for associations. It's great if you are interacting with your data using something other than ruby and mongoid, because it will make it perfectly clear how documents are related without having to consult the models for the relationships.

      Current handling:
      When referencing a document in another collection id's are used. E.g. a user document (stored in users) referencing a company (stored in companies):

      {"_id": 32, "user_name": "John Doe", "company_id": 1}

      {"_id": 1, "company_name": "Global Inc."}

      .

      Instead one should use DBRefs:

      {"_id": 32, "user_name": "John Doe", "company": { "$ref" : "companies", "$id" : 1 }}

      {"_id": 1, "company_name": "Global Inc."}

      For more details, see:
      http://www.mongodb.org/display/DOCS/Database+References

      Update: Clarified the examples

            Assignee:
            Unassigned Unassigned
            Reporter:
            sandstrom sandstrom
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: