[DOCS-10675] [Server] Revision on arrayToObject Created: 14/Aug/17  Updated: 30/Oct/23  Resolved: 30/Nov/22

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

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: David Hou
Resolution: Done Votes: 0
Labels: collector-298ba4e7, docs-triage, reopened
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

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

 Description   

Instead of using $literal in the two example, just wrap the array in another array.

Use a field expression instead of fixed values to show that it's possible (and that can't be done with $literal)



 Comments   
Comment by Githook User [ 12/Dec/22 ]

Author:

{'name': 'davidhou17', 'email': '55004296+davidhou17@users.noreply.github.com', 'username': 'davidhou17'}

Message: (DOCS-10675): Remove $literal from first $arrayToObject example (#2193)

  • change to brackets
  • tech review feedback
  • tech review feedback pt 2
Comment by Githook User [ 01/Dec/22 ]

Author:

{'name': 'davidhou17', 'email': '55004296+davidhou17@users.noreply.github.com', 'username': 'davidhou17'}

Message: (DOCS-10675): Remove $literal from first $arrayToObject example (#2193) (#2214)

  • change to brackets
  • tech review feedback
  • tech review feedback pt 2
Comment by Githook User [ 01/Dec/22 ]

Author:

{'name': 'davidhou17', 'email': '55004296+davidhou17@users.noreply.github.com', 'username': 'davidhou17'}

Message: (DOCS-10675): Remove $literal from first $arrayToObject example (#2193) (#2215)

  • change to brackets
  • tech review feedback
  • tech review feedback pt 2
Comment by Githook User [ 01/Dec/22 ]

Author:

{'name': 'davidhou17', 'email': '55004296+davidhou17@users.noreply.github.com', 'username': 'davidhou17'}

Message: (DOCS-10675): Remove $literal from first $arrayToObject example (#2193) (#2216)

  • change to brackets
  • tech review feedback
  • tech review feedback pt 2
Comment by Githook User [ 01/Dec/22 ]

Author:

{'name': 'davidhou17', 'email': '55004296+davidhou17@users.noreply.github.com', 'username': 'davidhou17'}

Message: (DOCS-10675): Remove $literal from first $arrayToObject example (#2193) (#2217)

  • change to brackets
  • tech review feedback
  • tech review feedback pt 2
Comment by Githook User [ 30/Nov/22 ]

Author:

{'name': 'davidhou17', 'email': '55004296+davidhou17@users.noreply.github.com', 'username': 'davidhou17'}

Message: (DOCS-10675): Remove $literal from first $arrayToObject example (#2193)

  • change to brackets
  • tech review feedback
  • tech review feedback pt 2
Comment by Asya Kamsky [ 01/Nov/22 ]

more specifically, using `$literal` is only useful when you have literal values you want to convert. However, usually the user will be converting fields and expressions using field values and that means they cannot use `$literal` so having every example only show how to do this with literal (aka constant) fields is not very useful!

Comment by Sarah Olson [ 31/Oct/22 ]

Have reviewed with asya.kamsky@mongodb.com. Her request is more user facing and solves for the question about whether a user wants to use a literal or no. 

Comment by Asya Kamsky [ 14/Aug/17 ]

Also, should add a note about what happens if the same field name ("k" value) appears more than once in the array - the first value ("v" value) wins.

edit this part was already done.

Comment by Asya Kamsky [ 14/Aug/17 ]

{ $arrayToObject: { $literal: [{ "k": "item", "v": "abc123"}, { "k": "qty", "v": 25 } ] } }

should just be

{ $arrayToObject: [ [{ "k": "item", "v": "abc123"}, { "k": "qty", "v": 25 } ] ] }

The reason you need second set of [ ] is because it tells arrayToObject there inside it are its arguments. If they are missing, it will interpret inner array [ ] and give an error that it got two arguments when it expected one.

$literal only works when everything is literal but if, say, 25 was coming from another field then you couldn't use $literal and would have to use [ ].

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