0

I'm looking for a way to clean document nested field, for example, consider I have a JSON object:

{
  fieldToClean: {
    fieldA: '..',
    fieldB: '..',
    fieldC: '..'
  }
}

I know that I don't need fieldB anymore. I found one solution that looks like:

var record = deepstream.record.getRecord('<proper path>')
record.whenReady(function(){
  var fieldToClean = record.get('fieldToClean')
  delete fieldToClean.fieldB
  record.set('fieldToClean', fieldToClean)
})

I wonder if deepstream provides something like:

record.delete('fieldToClean.fieldB')

or

record.set('fieldToClean.fieldB', undefined)

I wasn't able to find something like this in documentation.

Thank you for your time!

1 Answers1

1

There's actually an issue for this open, our main design question is around deleting an index in array. Is that a null or splice? Be great to have your feedback!

https://github.com/deepstreamIO/deepstream.io/issues/29

yasserf
  • 391
  • 1
  • 7
  • Perhaps, the case I'm asking about is a little bit different. The issue you sent me link is about removing an object from array field - a little bit more complicated. What I expected from deepstream is just removing by (sub)field name similar the way we modify record partially: record.set('myField.mySubfield', 'value'). So it could look like: record.delete('myField.mySubfield'). Let me know if it makes sense to create an issue for that or whether it's the same issue you're working on. – Vasiliy Sadokhin Apr 08 '16 at 08:36
  • When it comes to the opened issue I would expect it does splice so I won't have null elements in array field. Talking about the functionality I expect from example above I'd like to see that the field becomes undefined. – Vasiliy Sadokhin Apr 08 '16 at 08:40
  • We don't really want to use delete as its a destructive method and if called with undefined due to an error in code then you would accidently delete the data from the server itself. I'm also not sure if we would to add this logic to the server or the clients, as the only way we can do it on the client is by the method you stated, and via the server would require a new action on the protocol. Be great if you can add your notes onto the github issue, once we flesh out an API/design we can then start implementing this, as it's a very useful feature. – yasserf Apr 10 '16 at 13:04