0

How to prevent a property in mongo form being persisted in javascript?

I found a solution for this in Java world: Mongo - Ignore property from being persisted Basically, you just annotate a field with @Transient annotation.

Let's say I have an object and I dont want to store property transient:

{
  keepA: 1,
  keepB: 2,
  transinet: "don't persist me"
}

So after loading from mongoDb I would get this object:

{
  keepA: 1,
  keepB: 2
}
Community
  • 1
  • 1
Amio.io
  • 20,677
  • 15
  • 82
  • 117

1 Answers1

0

I have got a feeling. That in Java, Spring takes care of the creation of an object that will be persisted. So the framework strips out the annotated transient field. So mongoDb itself doesn't have any handles for transient fields.

If I am wrong please correct me.

Workaround

One could use lodash and its omit function. To strip unwanted fields.

Amio.io
  • 20,677
  • 15
  • 82
  • 117