Closed kipster521 closed 3 years ago
What type is styleType
? Before digging into the code (I do not remember :)), maybe Export-MdbcData
expects objects but finds scalars.
styleType
is a String. And the error was on the Get-MdbcData
.
You should use a projection expression, something like "{styleType: 1}"
or @{styleType=1}
.
0> help Get-MdbcData -Parameter Project
-Project
Specifies the projection expression, i.e. fields to be retrieved. The field _id is always included unless it is explicitly excluded.
The special value `*` used together with `-As <type>` tells to infer projected fields from the type.
Otherwise, the argument is either JSON or similar dictionary.
See also: https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/
Below is the updated code that worked. Thanks for your assistance.
Get-MdbcData -Project @{styleType=1; _id=0} | Export-MdbcData $Path -Append
I would like to select a field (styleType) from a collection and return its values into a file. This is what my code looks like:
Get-MdbcData -Collection $MyColl -Project styleType | Export-MdbcData $Path -Append
The error message I received is: JSON reader was expecting a value but found 'styleType'. Is Project not the correct parameter for selecting fields?