I have the below data where there are 2 bookingLineId fields. I would like to get the number of such duplicate bookingLineId fields in my collection. Please let us know on this.
If you inserted such a document into MongoDB only one of those fields would get created. Its not possible to store a document in MongoDB with two fields with the same key at the same level. The second key will overwrite the first.
BSON documents may have more than one field with the same name. Most MongoDB interfaces, however, represent MongoDB with a structure (e.g. a hash table) that does not support duplicate field names. If you need to manipulate documents that have more than one field with the same name, see the driver documentation for your driver.
Some documents created by internal MongoDB processes may have duplicate fields, but no MongoDB process will ever add duplicate fields to an existing user document.