Nested object write problem. Possibly indexing related

Hi.
I have been encountering an interesting problem for 2 months.

I have an object type which keeps a nested object inside. There are also several DBRefs in the main object. For the unknown circumstances (I do not exactly know how the problem is triggered), nested object begins to be not written under the main object for that collection during save operation. But DBRefs are fine.

So when I drop all the indexes for that collection and recreate them programmatically, this nested object problem is solved and begins to be written accordingly; until another time.

Do you have a suggestion/opinion about this?
Thanks.

Hi @kutay_YILDIRICI welcome to the community!

DBRefs are specific to a driver implementation, so it’s hard to tell what went wrong without knowing the driver you’re using. Could you post additional details:

  • What is the driver and the version you’re using
  • Could you share an example code that’s failing
  • Is this an intermittent issue, or is it happening all the time?

Best regards,
Kevin

1 Like

Hi @kevinadi
My problem is not about DBRefs, it is about nested documents. Once it is triggered, it is happening all the time, until I drop and recreate the indexes. After recreating the indexes and restarting the apps, documents begin to be written successfully.
Let me give you an example:

In my “POST” collection:
Successful record:

	_id
	text
	subPost --> nested document
	contact --> DBRef
	conversation --> DBRef

Fail record:

_id
text
contact → DBRef
conversation → DBRef

We use Mongo Atlas, v3.6.20 with 3 replica sets
We were using Mongo Java driver: 3.8.2 , but upgraded to Mongo Java driver: 3.11.2 recently. For both drivers, we are experiencing that problem.

Hi @kutay_YILDIRICI

Once it is triggered, it is happening all the time, until I drop and recreate the indexes. After recreating the indexes and restarting the apps, documents begin to be written successfully.

So the documents start to get written correctly once you dropped the indexes and restarted the app. Have you tried doing one of these but not both? E.g. try to restart the app and not dropping the indexes, or vice versa, to eliminate one or the other?

Also, how are the nested document created? Are they created in a separate app, or a separate function within the code? Could you try to e.g. insert some print statements in the function that create the nested document to ensure that they’re called?

On another note, could you remember in what situation does the nested document stop being created? Is it just random?

Best regards,
Kevin

Hi @kevinadi
Dropping the indexes is a must. But we did not try “drop the indexes and not restart the app” option, because by restarting the app, we can recreate the indexes dynamically. Maybe we also can try creating these indexes manually.

There is also another application, a “consumer” application for inserting these documents. It reads from a queue, maps that value to the nested document, creates the main document and adds the nested document to main document, etc. We run and debugged that consumer application on our local. After the saving operation, returned/saved object contains the nested object, but actually the nested document is not in the main document in the Mongo collection.

We don’t know what situation triggers that problem. I don’t think it is a random thing. Maybe it is not just directly indexing related problem; also Spring data and persistence can be involved.