Details
-
Improvement
-
Resolution: Unresolved
-
Major - P3
-
None
-
None
-
Query Optimization
Description
As you can see below - it just happens to return an empty object, but proceeds without error. It seems better to either (a) error or (b) return an array. We don't have a 'set' data type in the BSON spec, so I don't see how we could get it to work and round trip seamlessly, but this experience isn't great.
> db.foo.aggregate([{
|
$project: {
|
js_res: {
|
$function: { |
lang: "js", |
body: function() { |
return new Set([1, 2]); |
},
|
args: []
|
}
|
}
|
}
|
}])
|
{ "_id" : ObjectId("5f3c24f10efd1cb7f0a88f4a"), "js_res" : { } } |
{ "_id" : ObjectId("5f3c24f60efd1cb7f0a88f4b"), "js_res" : { } } |
{ "_id" : ObjectId("5f47f9411945d1527c6b0368"), "js_res" : { } } |
{ "_id" : ObjectId("5f47f9c71945d1527c6b0369"), "js_res" : { } } |
{ "_id" : ObjectId("5f47fa721945d1527c6b036a"), "js_res" : { } } |
As a workaround, you can use the [...set] syntax to expand the set into an array:
> db.foo.aggregate([{
|
$project: {
|
js_res: {
|
$function: { |
lang: "js", |
body: function() { |
return [...new Set([1, 2])]; |
},
|
args: []
|
}
|
}
|
}
|
}])
|
{ "_id" : ObjectId("5f3c24f10efd1cb7f0a88f4a"), "js_res" : [ 1, 2 ] } |
{ "_id" : ObjectId("5f3c24f60efd1cb7f0a88f4b"), "js_res" : [ 1, 2 ] } |
{ "_id" : ObjectId("5f47f9411945d1527c6b0368"), "js_res" : [ 1, 2 ] } |
{ "_id" : ObjectId("5f47f9c71945d1527c6b0369"), "js_res" : [ 1, 2 ] } |
{ "_id" : ObjectId("5f47fa721945d1527c6b036a"), "js_res" : [ 1, 2 ] } |
Attachments
Issue Links
- is related to
-
SERVER-34281 ES6 arrow functions (lambdas) do not work with map-reduce
-
- Closed
-
-
SERVER-46243 Support ES6 Map object in MongoDB shell
-
- Backlog
-
-
SERVER-31551 Create a test which enumerates the objects available in server side JS environments
-
- Closed
-
-
SERVER-32665 tojson should print the elements when passed a Set object
-
- Closed
-
- related to
-
DOCS-13861 JS objects like 'Set' do not work well in user-defined JS like $accumulator
-
- Closed
-