Invalid character '(' after object key

Hi All,

I need to get records from a collection by doing a lookup to match two fields of another collection. We expect to return one field from each of the collections.

I composed a query in the mongodbexport as
“–query '{party:{aggregate([{$lookup:{from:“party_preference_list”,as:“preference”}},{$match:{”$and":[{“preference.party_preferences.selected_preference_value”:“PAPER”}, {“preference.party_preferences.preference_code”:“EOB”}]}},{$project:{“party_role”:1,“preference.card_id”:1}}])}}’"

When I ran mongoexport, it prompted me below error messages:
“error validating settings: query ‘[123 112 97 … ]’ is not valid JSON: invalid character ‘(’ after object key
… try ‘mongoexport --help’ for more information”

I would very appreciate if someone can help on fixing the query.

Thanks, YC

Hello @Yichang_Chen, welcome to the MongoDB forum.

There is no feature to specify an aggregation query with the --query option of the mongoexport. See the feature request: Support aggregation framework queries in mongoexport.

But, there are other ways to use aggregation results with mongoexport:

  • An aggregation’s output documents can be written to a collection using the $out pipeline stage. The result collection can be used as input to the export.
  • Another way is to use Views. An aggregation pipeline can be specified with creating a view. Then the query on the view can be used with the --query option.