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

Kinto automatically create non existing collection #2911

Open
SimonKlausLudwig opened this issue Nov 10, 2021 · 2 comments
Open

Kinto automatically create non existing collection #2911

SimonKlausLudwig opened this issue Nov 10, 2021 · 2 comments
Labels
stale For marking issues as stale. Labeled issues will be closed soon if label is not removed.

Comments

@SimonKlausLudwig
Copy link

Is there a way to create the collection on the fly ?

Lets say im trying to create a record for the collection 'user' and user collection does not exists yet. Is it possible to create a default collection right away ?

@leplatrem
Copy link
Contributor

Currently we only implemented this behavior on the default_bucket plugin, which has a lot of other specificities.

One possibility is to use the concurrency control requests headers in your client, to create only if it doesn't exist.

$ http PUT https://kinto.dev.mozaws.net/v1/buckets/a "If-None-Match: *" -a user:pass
HTTP/1.1 201 Created
Access-Control-Expose-Headers: Alert, Content-Length, Backoff, Retry-After, Content-Type
Connection: keep-alive
Content-Length: 152
Content-Security-Policy: default-src 'none'; frame-ancestors 'none'; base-uri 'none';
Content-Type: application/json
Date: Wed, 10 Nov 2021 14:48:40 GMT
ETag: "1636555720093"
Last-Modified: Wed, 10 Nov 2021 14:48:40 GMT
Server: nginx
X-Content-Type-Options: nosniff

{
    "data": {
        "id": "a",
        "last_modified": 1636555720093
    },
    "permissions": {
        "write": [
            "basicauth:631c2d625ee5726172cf67c6750de10a3e1a04bcd603bc9ad6d6b196fa8257a6"
        ]
    }
}

If it exists it will return 412 (that your client code can ignore on purpose)

$ http PUT https://kinto.dev.mozaws.net/v1/buckets/a "If-None-Match: *" -a user:pass
HTTP/1.1 412 Precondition Failed
Access-Control-Expose-Headers: Alert, Content-Length, Backoff, Retry-After, Content-Type
Connection: keep-alive
Content-Length: 162
Content-Security-Policy: default-src 'none'; frame-ancestors 'none'; base-uri 'none';
Content-Type: application/json
Date: Wed, 10 Nov 2021 14:48:42 GMT
ETag: "1636555720093"
Last-Modified: Wed, 10 Nov 2021 14:48:40 GMT
Server: nginx
X-Content-Type-Options: nosniff

{
    "code": 412,
    "details": {
        "existing": {
            "id": "a",
            "last_modified": 1636555720093
        }
    },
    "errno": 114,
    "error": "Precondition Failed",
    "message": "Resource was modified meanwhile"
}

@slav0nic
Copy link
Contributor

also you can manually create empty collection based on notification on backend level.
For example: create profile collection when new account created.

@alexcottner alexcottner added the stale For marking issues as stale. Labeled issues will be closed soon if label is not removed. label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale For marking issues as stale. Labeled issues will be closed soon if label is not removed.
Projects
None yet
Development

No branches or pull requests

4 participants