[DOCS-10781] Mongo shell cursor tailable function ignores isAwaitData flag Created: 12/Sep/17  Updated: 30/Oct/23

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Major - P3
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 1 year, 14 weeks, 2 days ago
Epic Link: DOCSP-1769

 Description   

Creating a tailable cursor on a capped collection with isAwaitData: false should not block when calling hasNext() on the cursor according to this docs page

However, the following script will still block on hasNext calls:

db.coll.drop();
db.createCollection("coll", {size: 100, capped: true});
for (var i = 0; i < 10; i++) db.coll.insert({x: i});
 
// create a tailable cursor
var cursor = db.coll.find().tailable({isAwaitData: false});
 
// exhaust cursor
while (cursor.hasNext()) cursor.next();
 
// the following blocks for one second despite isAwaitData being false
cursor.hasNext();

This is reproducible using mongo shell version v3.4.7 as well as on master, v3.5.12-204-ge2defe9a85.

Using mongoreplay, it shows the shell passes awaitData:true to the find command regardless of the value of isAwaitData.

12 Sep 17 11:48 -0400 (Connection: 30:1043)  op_command find test Request:{"command_args":{"awaitData":true,"filter":{},"find":"coll","tailable":true},"input_docs":[],"metadata":{}}

So it looks like a shell issue, not a server issue. I think it is caused from the definition of tailable being incorrect (or the docs are incorrect). The function in shell/query.js for tailable is expecting a boolean:

DBQuery.prototype.tailable = function(awaitData) {
    this._checkModify();
    this.addOption(DBQuery.Option.tailable);
 
    // Set await data if either specifically set or not specified
    if (awaitData || awaitData == null) {
        this.addOption(DBQuery.Option.awaitData);
    }
 
    return this;
};



 Comments   
Comment by Education Bot [ 31/Oct/22 ]

Hello! This ticket has been closed due to inactivity. If you believe this ticket is still important, please reopen it and leave a comment to explain why. Thank you!

Comment by Kevin Albertson [ 12/Sep/17 ]

If it's the docs that need to be updated I'll move it to the docs project. I assumed the docs were right since it seems like passing an object follows our usual convention. Also git blaming that function it looks like it was last changed in 2015.

Comment by Max Hirschhorn [ 12/Sep/17 ]

kevin.albertson, all JavaScript Objects are truthy, so I think the line that says

var cursor = db.coll.find().tailable({isAwaitData: false});

should just be

var cursor = db.coll.find().tailable(false);

Should this ticket just be moved to the DOCS project if the cursor.tailable() page is suggesting that the option be wrapped in an {isAwaitData: false} object?

Generated at Thu Feb 08 08:01:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.