[CSHARP-1939] Add an aggregation expression to convert an object to an array of key, value pairs Created: 13/Mar/17  Updated: 13/Apr/22

Status: Backlog
Project: C# Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Unassigned
Resolution: Unresolved Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-18794 Add an aggregation expression to conv... Closed
is depended on by DRIVERS-358 Aggregation Framework Support for 3.6 Closed
Epic Link: Aggregation
Server Compat: 3.4, 3.5

 Description   

In many cases, it would be useful to convert an object to an array. We should add an aggregation expression to do so. For example, it could be called $objectToArray, and do something like this:

> db.foo.insert({_id: 0, subDoc: {a: 1, b: 3, c: "example"}});
> db.foo.aggregate([{$project: {expanded: {$objectToArray: "$subDoc"}}}])
{_id: 0, expanded: [{k: "a", v: 1}, {k: "b", v: 3}, {k: "c", v: "example"}]}

Original Description

Currently, if a collection contains the following document:

{_id: 0, data: {a: 1, b: 2, c: 3}}

There is no way to unwind that one document into the following three documents:

{_id: 0, data: {a: 1}}
{_id: 0, data: {b: 2}}
{_id: 0, data: {c: 3}}


Generated at Wed Feb 07 21:41:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.