Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the script am running in mongoshell to understand the usage of $mergeobjects operator in aggregation. I want to see the output from this operator($mergeobjects)
So than i can clearly understand the functionality of this operator.

but when run this script am getting below mentioned error.

2019-08-05T12:39:35.309+0530 E QUERY    [js] SyntaxError: missing ] after element list @(shell):2:17


Am new to mongodb.understanding this from SQL perspective.
Any solution on this error would be greatly appreciated.

What I have tried:

db.collection.aggregate([
    $mergeObjects: [ { _id: "$_id", first: "", last: "" }, "$name" ] 
])
Posted
Updated 4-Aug-19 22:01pm

1 solution

You have the square brackets and curly braces in the wrong places. See $mergeObjects (aggregation) — MongoDB Manual[^].
 
Share this answer
 
Comments
Member 11337367 5-Aug-19 4:46am    
from that link only i generated this script but still failing to execute the script.can you pls elaborate the issue?so that ill know where exactly it went wrong?
Richard MacCutchan 5-Aug-19 4:52am    
Look where you are using square brackets and curly braces. According to the documentation you have them the wrong way round.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900