Should I keep null in object or empty {}


"Parentnode": {}


"Parentnode": {"n1":"abc","n2":"xyz"}


i have one key “parentnode” in mongo db. which can have data and could be nothing also. so should i keep {} or null.

yours sincerely.

Mongo DB have a flexible schema. Even if you haven’t or forgot to define a key in your data model it will accept when you will insert the data it will accept it. The format should only be followed by the key you have specified in yours schema.

question was which one is better , null or {}

My preference would be in order

  1. not have the field at all so that I can use $exists on the field
  2. have the field with the null value so that I can test { ‘Parentnode’ : null }