[SERVER-51427] Ensure that find shell helper supports 'let' variables Created: 07/Oct/20  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Jason Price Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: qopt-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-51362 Ensure that update and delete shell h... Closed
Assigned Teams:
Query Optimization
Participants:

 Description   

The find command supports let parameters, but the db.collection.find() shell helper does not.

Also, see this JIRA:
https://jira.mongodb.org/browse/SERVER-51362

The following test works:

db.cakeFlavors.drop()
 
db.cakeFlavors.insert( [
      { _id: 1, flavor: "chocolate" },
      { _id: 2, flavor: "strawberry" },
      { _id: 3, flavor: "cherry" }
 ]  )
 
db.cakeFlavors.runCommand( {
   find: db.cakeFlavors.getName(),
   let : { targetFlavor: "chocolate" },
   filter: { $expr: { $eq: [ "$flavor", "$$targetFlavor" ] } },
} )

But the corresponding command using the shell helper fails. I'm not 100% sure I'm executing it properly, as there is no test case for it.

db.cakeFlavors.find(
  { "$flavor": { "$$targetFlavor" } },
  { let: { targetFlavor: "chocolate" } }
)

I also tried this, which also generated an error:

db.cakeFlavors.find(
  { "$flavor": { "$$targetFlavor" } },
  let: { targetFlavor: "chocolate" } 
)



 Comments   
Comment by Jason Price [ 09/Oct/20 ]

Per a Slack conversation with katherine.wu, the full list of find helper commands to add the let option is:

db.collection.find
db.collection.findAndModify (this one already works in my testing)
db.collection.findOne
db.collection.findOneAndDelete
db.collection.findOneAndReplace
db.collection.findOneAndUpdate

Generated at Thu Feb 08 05:25:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.