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

array operator #96

Open
bwgjoseph opened this issue Jun 15, 2021 · 5 comments
Open

array operator #96

bwgjoseph opened this issue Jun 15, 2021 · 5 comments
Assignees
Labels
no-op no further action is needed

Comments

@bwgjoseph
Copy link
Owner

Hi,

Something that I've missed out again but is there an existing feature to perform array operation such as $push, $pull, $each, $pop, etc as described in here

I don't think I've seen it mentioned anywhere in the documentation, and it has quite a common use case to manipulate an array within a document.

Thanks

@AV25242
Copy link
Collaborator

AV25242 commented Jun 15, 2021

Although I understand the need, but there are work arounds like you can select the array update it using native JSON operators and then use the update method to update the document.

@AV25242 AV25242 assigned bwgjoseph and unassigned AV25242 Jun 15, 2021
@AV25242 AV25242 added the no-op no further action is needed label Jun 15, 2021
@bwgjoseph
Copy link
Owner Author

Does op-op mean it will not be considered even post GA? Is it because that the underlying Couchbase database does not support it natively to perform array operations on the document?

I know that we can grab the document and perform the action ourselves, but it's not safe as compared to offloading to the database to do the work. Consider the following scenario where

Request 1 grab the document, make the changes manually to the document, and update it to the database and at the same time Request 2 also grab the document before the changes are made and make changes to the document array.

// req1
.findById('12345');
// req2
.findById('12345');
// req1
.updateById('12345', { comments: [<whatever values before>, 'abcde'] });
// req2
.updateById('12345', { comments: [<whatever values before>, 'defgc'] });
// end state would be
comments: [<whatever values before>, 'defgc']

I understand this might not be the best example since there are also other scenarios where this would occur and developer have to manage themselves via cas or __v (in mongoose), but if there the ability to update the array via $push, $pull, etc, it could be written as such

// req1
.updateById('12345', { comments: { $push: ['abcde'] } });
// req2
.updateById('12345', { comments: { $push: ['defgc'] } });
// end state would be
comments: [<whatever values before>, 'abcde', 'defgc']

As such, this is safe for the developer, and know that there won't be conflict. Without it, there is a lot more work that needs to be done on the developer side to ensure the safety of document conflict.

Ease of array/object manipulation should be something that is provided by the driver that also ensures the safety of the document (as much as possible)

@bwgjoseph bwgjoseph assigned AV25242 and unassigned bwgjoseph Jun 16, 2021
@AV25242
Copy link
Collaborator

AV25242 commented Jun 29, 2021

I understand, however we dont support sub-document operations yet. We will have to get there first and then apparently think of this. Thats why its listed as no-op atleast for now.

@AV25242 AV25242 assigned bwgjoseph and unassigned AV25242 Jun 29, 2021
@bwgjoseph
Copy link
Owner Author

Alright, it is quite an important feature to have. So long that this feature is planned to be added, I think it's fine to be lacking for now. Thanks

@bwgjoseph bwgjoseph assigned AV25242 and unassigned bwgjoseph Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-op no further action is needed
Projects
None yet
Development

No branches or pull requests

2 participants