Strange behavior after setting up VPC with GCP: find() wrongfully returns 0 matches


I am running a Node.js backend with mongoose in Google Cloud, Cloud Run, and a mongoDB cluster in Atlas. I have now configured VPC peering with VPC serveless connector, as explained in the set up guide provided by Google:

All statuses are green for the VPC connection on both sides, and my backend successfully connects to the cluster through the VPC, using the private connection string.

But turns out not all is well; something very strange is happening: Certain (not all) find() queries return 0 matches even though there actually are matches. There are no errors, I just get 0 results.

If I run the same queries outside of the VPC, everything works fine.

Has anyone else experienced this and found a solution?

Thank you!

I figured out what was causing the issue. Previously, my connection string included the database name at the end, like <connection_ui>/dbName, but when I copied the new private connection string from Atlas, this part was not included anymore, so I was effectively querying an empty database.

Lesson learned…

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.