[COMPASS-7320] Document Count UI Not Updating When Inserting Document from NodeJS Created: 10/Oct/23  Updated: 27/Oct/23  Resolved: 11/Oct/23

Status: Closed
Project: Compass
Component/s: None
Affects Version/s: 1.40.2
Fix Version/s: No version

Type: Bug Priority: Trivial - P5
Reporter: Sacha Davidson Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS: Windows 10 Home
node.js / npm versions:
Node Version - Node.js v18.16.0 &&
NPM Version - mongodb: "^6.1.0"
Additional info: This issue occurred on various devices (other students in my class had this occur on their machines as well, all Windows 10 or Windows 11, same Node and npm versions)


Attachments: PNG File Insert1NodeJsCompassDocumentAfterDropDB.PNG     PNG File Insert1NodeJsCompassDocumentAfterDropDBPt2.PNG    
Documentation Changes: Not Needed

 Description   

Problem Statement/Rationale

What is going wrong? What action would you like the Engineering team to take?
From a Node.js application, when using the insertOne() function to add a new document to a collection, the number of documents displayed in Compass when the collection is selected and refreshed remains the same as it was before the new document is inserted. (refreshing documents populates the new record and increases the count next to the refresh button, but not update the number displayed in the upper right side.)

Please be sure to attach relevant logs with any sensitive data redacted.
How to retrieve logs for: Compass; Shell
User is unsure about what data, if any, should be redacted from log.

Steps to Reproduce

How could an engineer replicate the issue you’re reporting?

1. Open a collection in Compass GUI and remain on the Documents tab for the collection (note the number of documents)
2. Insert a new record/document from a Node.js application using the insertOne() method on the collection. 

3. Click 'Refresh documents' in the Compass GUI

Expected Results

1. The newly inserted document appears along with any previously existing documents. 

2. The count of documents increases where it is displayed next to the 'Refresh documents'.
3. The count of documents to the right-hand side of the collection name increases.

Actual Results

1. The newly inserted document appears along with any previously existing documents. 

2. The count of documents increases where it is displayed next to the 'Refresh documents'.
3. The count of documents to the right-hand side of the collection name DOES NOT increase.

Additional Notes

This is my first Jira ticket outside of school, but I hope it is helpful. This was also my very first time using the Compass GUI (and the second time using MongoDB). My instructor recommended reporting the issue, in case this was not the intended behaviour.



 Comments   
Comment by Le Roux Bodenstein [ 11/Oct/23 ]

Hi Sacha

This is unfortunately "by design". The number top-right comes from collection metadata (see https://github.com/mongodb-js/compass/blob/af2e74e30317d540de266db5ca5f43194ef60d21/packages/data-service/src/data-service.ts#L958), ie. the same as if you do db.collection.estimatedDocumentCount() and this can be out of sync. To get an accurate document count you can use db.collection.countDocuments(), however that might do a collection scan which can be slow in some situations which is why compass doesn't use that there.

Comment by PM Bot [ 10/Oct/23 ]

Hello sacha@davidson.solutions, thank you for reaching out to us! The team will review your issue and get back to you soon as soon as possible.

Please review your issue to ensure you've included your environment details and have attached relevant logs (with any sensitive data redacted), so that we're best able to provide you a timely and thorough response. Thanks again!

Generated at Wed Feb 07 22:46:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.