-
Notifications
You must be signed in to change notification settings - Fork 98
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
Allow modelKey to be a nested field #638
Comments
Hello @doceme thanks for reaching out, trying to understand the ask by confirming some assumptions here. I pulled down the lounge project - https://github.com/cvent/lounge and I see that in
Assuming while migrating to Ottoman you have have defined in the main Schema a field And, what you have tried so far is const schema = new Schema({ name: String, age: Number, metadata : {doc_type:String} }); and it doesnt work and you want to know how can I achieve it or how do I contribute a PR to make it happen Is this correct ? @gsi-alejandro can you please followup ? |
Hello @AV25242. Thanks for responding so quickly. The gist of what you have described is correct, except for different field names. The lounge project doesn't have a specific requirement to use a metadata or type field, however all of the documents in my project do have a base schema like this:
I realize that having a field named What I have tried with ottoman is:
And if I change:
to
everything works as expected. |
Yeah that is correct |
My problem is unrelated to |
Understood. Team is looking to see what can be done. Thanks for the detail explanation |
hi, @doceme What Couchbase Server version are you using? |
Hello @gsi-alejandro, we're using Couchbase Server version 7.0.3 at the moment. |
Hello @doceme the concept of
Having said all that one workaround (in the meanwhile) for you could be to write a SQL++ update statement on all the documents that basically adds a _type field with the value of meta.type and you can continue with the migration. On a side note I see that you are on 7.x but using |
Hello @AV25242, thanks for your consideration of this request. I understand that ottoman creates a GSI to handle the |
hi @AV25242, @doceme It will be released in the next iteration. (dev -> master) e.g. will work for this schema const baseSchema = lounge.schema({
metadata: {
doc_type: String,
createdAt: Date,
updatedAt: Date
}
}) |
Thanks @gsi-alejandro! I have tested this PR on my project and it fixes the issue for
and here is how a document is saved using this schema:
Would it be possible to have createdAt and updatedAt also stored in metadata? Should I create a separate issue for this? I really appreciate your help with this. |
hi @doceme The PR just has changes to support nested value in the We'll create a new ticket this week to handle timestamps the same way. (I'll prepare a proposal in order to be approved and be able to proceed into the implementation.) I will keep you updated about timestamps with progress. |
@doceme if you want to try to build the schema this way: const metadataSchema = new Schema(
{
doc_type: String,
},
{ timestamps: true },
);
const schema = new Schema({
name: String,
age: Number,
metadata: metadataSchema,
}); Note: We probably should update something else and of course add some tests for it, but should work. |
hi @doceme I already did and test the changes need for timestamps to work in a nested schema. The changes are in dev branch, they will be released in the next release These schemas will work for your use case const metadataSchema = new Schema(
{
doc_type: String,
},
{ timestamps: true },
);
const schema = new Schema({
name: String,
age: Number,
metadata: metadataSchema,
}); Notice: you can reuse I hope this has been helpful, cheers/ |
@gsi-alejandro Thanks for the suggestion. That would work if we were using Date for the createdAt and updatedAt fields, but we're actually using a Number as described here: https://ottomanjs.com/guides/schema.html#option-timestamps. I used a Date field in my previous example because the code worked to at least store a document in the database without giving an error. If I use a Number field, I get: |
@gsi-alejandro Wonderful! Thank you so much. We've been wanting to transition our project to ottoman for a while now. This will definitely make it possible for us to do so. |
nice to hear that @doceme If you need something else just create a ticket or if you have any ideas to improve are welcome too, we're continuously enhancing Ottoman. Feel free to close this ticket if there aren't any remaining issues. have a nice day, happy coding 🎉 |
# [2.2.0](http://github.com/couchbaselabs/node-ottoman/compare/v2.1.0...v2.2.0) (2022-03-29) ### Features * **hooks:** trigger embed schema hooks ([9389dfe](http://github.com/couchbaselabs/node-ottoman/commit/9389dfefe9ea49cb9f302152abeb24da9f391c80)) * **ottoman:** add support for nested modelKey ([6bcb9fc](http://github.com/couchbaselabs/node-ottoman/commit/6bcb9fc9dee7084ff259b2db8660326cb946a8a7)), closes [#638](http://github.com/couchbaselabs/node-ottoman/issues/638)
Hello @doceme did it help, we released it with 2.2.0. please let us know. |
Hi @AV25242. Yes, we are currently in the process of migrating from lounge to ottoman using version 2.2.0. We haven't hit any show-stoppers yet. Thanks! |
I am trying to migrate my existing project from lounge to ottoman, but my existing project stores type in a
meta
object. Since this is a nested field, I'm not currently able to setmodelKey
tometa.type
without getting a CouchbaseInternalServerFailureError
. I would issue a pull-request, but I would need some help on where to get started with this change. I'm not sure how difficult it would be. Thanks.The text was updated successfully, but these errors were encountered: