node-ottoman icon indicating copy to clipboard operation
node-ottoman copied to clipboard

unset option support

Open rajasekar-mu opened this issue 3 years ago • 3 comments

Hi ,

I need to unset the specific key in model.

ex: {"name":"David","status":1,"grade":"2C"} expect result to delete the grade key in above document

result: {"name":"David","status":1},

I know UNSET Clause in n1ql, similar option is support Ottoman Model?

Thanks,

rajasekar-mu avatar May 20 '22 14:05 rajasekar-mu

hi @rajasekar-mu

Ottoman's model doesn't have any implementation for UNSET, but Maybe you can use replaceById to achieve it:

syntax:

Model.replaceById(id, newDocument);

e.g.

User.replaceById("12345",  {"name":"David","status":1});

result: {"name":"David","status":1,"grade":"2C"} ==> {"name":"David","status":1}

Note: If you need to execute it to update your entire documents in a collection, you can execute a migration or similar using an N1QL query.

gsi-alejandro avatar May 24 '22 15:05 gsi-alejandro

Thanks @gsi-alejandro ,

If we have 30+ keys & subdocuments, its difficult to update replaceById. So could you add this feature.

rajasekar-mu avatar May 30 '22 15:05 rajasekar-mu

hi @rajasekar-mu

The team will discuss this feature request.

I will notify you about the progress.

Best Regards.

gsi-alejandro avatar May 31 '22 16:05 gsi-alejandro