You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using SQL, it is easy to insert a document into a specific bucket.
I was trying to do the same using the Java API without using the Database.command() method, but I'm not sure what is the correct way of doing it.
In my use case, I create new buckets dynamically (they represent time ranges), so I don't have the full list of buckets at the time the Type is created, but for simplicity the sample code below assumes that the bucket already exists:
MutableDocument document = database.newDocument("product");
// omitted code to set property values
Bucket bucket = database.getSchema().getBucketByName("201407");
bucket.createRecord(document, true);
document.save();
Is this the right way? I have a few doubts:
1 - do buckets exists independently from types? When a new Type is created, the db engine automatically creates buckets for the type, but if I want to create a custom bucket I have to first create it from the schema and then add it to the Type. If I understand correctly, this is done to allow working in schema-less mode
2 - do I always need to call document.save()? In some examples it is called, in others it isn't
3 - what is the exact meaning of the discardRecordAfter parameter of the createRecord method? What value would produce the same result that is obtained by using "INSERT INTO product BUCKET 201407 " etc..?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Using SQL, it is easy to insert a document into a specific bucket.
I was trying to do the same using the Java API without using the Database.command() method, but I'm not sure what is the correct way of doing it.
In my use case, I create new buckets dynamically (they represent time ranges), so I don't have the full list of buckets at the time the Type is created, but for simplicity the sample code below assumes that the bucket already exists:
Is this the right way? I have a few doubts:
1 - do buckets exists independently from types? When a new Type is created, the db engine automatically creates buckets for the type, but if I want to create a custom bucket I have to first create it from the schema and then add it to the Type. If I understand correctly, this is done to allow working in schema-less mode
2 - do I always need to call document.save()? In some examples it is called, in others it isn't
3 - what is the exact meaning of the discardRecordAfter parameter of the createRecord method? What value would produce the same result that is obtained by using "INSERT INTO product BUCKET 201407 " etc..?
Beta Was this translation helpful? Give feedback.
All reactions