Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subdocument IDs handling not clear #58

Open
mauriceKA opened this issue May 20, 2016 · 2 comments
Open

Subdocument IDs handling not clear #58

mauriceKA opened this issue May 20, 2016 · 2 comments

Comments

@mauriceKA
Copy link

I would like to have stable IDs (uuids) also on sub documents of a collection. This is what I experience:

Again, I have a simple model:

server.resource('test', { 
    p1: [{
        p2 : String,
    }]
});

Then, I want to give the documents under p1 a uuid. When I POST this example JSON ...

{
    "p1": [
        {
            "p2": "foo"
        }
    ]
}

... I get back a JSON like this immediately in the result:

{
  "p1": [
    {
      "p2": "foo",
      "_id": "573f04dccaa53f2c00925336"
    }
  ],
  "id": "e6b20bd0-6c18-4095-b729-bc1156e5fb2f"
}

Why is the inner ID called "_id" and not "id"? And why is the inner ID not in in UUID format like the outer ID but some internal (probably Mongo?) format?

When I query for it later, at least the "_id" field is now correctly called "id", but this is confusing. Why not already in the return of the POST? And again, the id is not a UUID.

{
  "p1": [
    {
      "p2": "foo",
      "id": "573f04dccaa53f2c00925336"
    }
  ],
  "id": "e6b20bd0-6c18-4095-b729-bc1156e5fb2f"
}

Also when I pre-generate a UUID and try to submit it along in the POST like ...

{
    "p1": [
        {
            "p2": "foo",
            "id": "2df2aa9e-1d4a-418b-9ecd-cd7f5de4bbd6"
        }
    ]
}

the UUID is overwritten and I get back a different, regular ID in the repsonse:

{
  "p1": [
    {
      "p2": "foo",
      "_id": "573f06ebcaa53f2c00925337"
    }
  ],
  "id": "8587bb44-ebe6-4db7-9532-7e7fa02ba36e"
}

Could you fix this, so that also for sub-documents UUIDs are generated?

@zackyang000
Copy link
Owner

_id should be remove, I will add a field named id which generated by UUID to instead of it.

Then, follow this route should be support:

/p1('8587bb44-ebe6-4db7-9532-7e7fa02ba36e')/p2
/p1('8587bb44-ebe6-4db7-9532-7e7fa02ba36e')/p2('some uuid')

@mauriceKA
Copy link
Author

Thank you very much for your prompt reaction. Hope that my input helps a little making your library production-ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants