-
Notifications
You must be signed in to change notification settings - Fork 3
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
Complete overwrite of existing document - upsert #23
Comments
Hello @mreis92 , According to the documentation, a You can retrieve storage adapter of a model from Model.storage property. I should probably add brief explanation of individual classes in the doc. I realize now that people who don't know internal implementation design might be confused/unsure what's the purpose of some classes. Thanks. |
Thanks for the prompt reply @fogine . I understand now, and using Am I missing some way of achieving what I want while maintaining the aforementioned capabilities? My alternative approach was to do something like: let saveOptions = {
isNewRecord: !someId,
key: someId
}
let model = Model.build(myModel, saveOptions);
return model.save(); ,but this did not appear to replace the document as one would expect. In fact, the only time when I can see the changes that I make is when I am creating the document. Regarding documentation, I feel like a brief description could help, even in exploring the exposed functionalities. Let me know if I can help in the documentation somehow! |
@mreis92 , you could create your own var couchbase = new couchbaseODM({
bucket: bucket,
instanceMethods: {
upsert: function() {
var doc = this;
return this.getGeneratedKey().bind({}).then(function(key) {
this.key = key;
return doc.getSerializedData();
}).then(function(data) {
return doc.getStorageAdapter().upsert(this.key, data);
});
}
}
}); The above example adds I have been thinking about adding support for About the documentation, if you think there is something which could be better/more documented or a specific tutorial is missing which would have helped you with understanding the |
@mreis92 , the code example you provided should preform |
@mreis92 , I've just realized that my response above stating that building new model instance with |
@fogine It makes sense. For my particular use case, I wound't have that problem because I don't have IMO, overwriting existing I've noticed in the documentation that the PS: Regarding documentation, I'll see if I can contribute on some meaningful examples (if not in the method documentation, maybe add some more examples to the tutorials :) ) |
Hello! I have noticed in your documentation that we can perform an upsert using a StorageAdapter. My question here is: How to obtain the storage adapter in order to perform this upsert operation?
Thank you!
What you are doing?
Trying to completely replace an existing document.
What do you expect to happen?
The document to be completely replaced. Using a combination of update or build and replace does not do the trick.
What is actually happening?
I cannot retrieve the storageAdapter
Couchbase SDK version: 2.2.2
Couchbase Server version: 4.1 Community
CouchbaseODM version/branch: v1.0.1
The text was updated successfully, but these errors were encountered: