Closed saptaji closed 3 years ago
Not sure what you mean. Here are some bits you may get:
Import-Module Mdbc
Connect-Mdbc -NewCollection
@{
_id = 0
Agent = @{
Os = 1
AgentDevice = @{
AgentId = 1
DeviceId = 1
}
}
} |
Add-MdbcData
$r = Get-MdbcData
'ToString()'
$r.ToString()
'Print()'
$r.Print()
# is this it?
'Agent.AgentDevice.AgentId'
$r.Agent.AgentDevice.AgentId
Output:
ToString()
{ "_id" : 0, "Agent" : { "Os" : 1, "AgentDevice" : { "DeviceId" : 1, "AgentId" : 1 } } }
Print()
{
"_id" : 0,
"Agent" : {
"Os" : 1,
"AgentDevice" : {
"DeviceId" : 1,
"AgentId" : 1
}
}
}
Agent.AgentDevice.AgentId
1
This is the command that I am using:
$deviceFielddProjection = '{ "_id": 0,"Agent.Os": 1,"Agent.AgentDevice.AgentId": 1,"Agent.AgentDevice.DeviceId": 1}'
Get-MdbcData -As PS -Project $deviceFielddProjection
If I didn't specify '-Project' parameter, it will return all of the data successfully. The data that I posted in this ticket is only a subset of it. I want to reduce the amount of data that is being transferred that's why I am using the '-Project' parameter.
Update: When I removed '-As PS', the Projection works fine.
$deviceFielddProjection = '{ "_id": 0,"Agent.Os": 1,"Agent.AgentDevice.AgentId": 1,"Agent.AgentDevice.DeviceId": 1}'
Get-MdbcData -Project $deviceFielddProjection
I am still interested in specifying '-As PS' parameter. If you can provide an example, I appreciate it.
This is explained better. I think it works, it's just PS formatting of PS objects with nested data confuses you.
Import-Module Mdbc
Connect-Mdbc -NewCollection
@{
_id = 0
Agent = @{
Os = 1
AgentDevice = @{
AgentId = 2
DeviceId = 3
}
}
} |
Add-MdbcData
$deviceFielddProjection = '{"_id": 0, "Agent.Os": 1, "Agent.AgentDevice.AgentId": 1, "Agent.AgentDevice.DeviceId": 1}'
$r = Get-MdbcData -As ps -Project $deviceFielddProjection
$r | ConvertTo-Json -Depth 99
Output:
{
"Agent": {
"Os": 1,
"AgentDevice": {
"DeviceId": 3,
"AgentId": 2
}
}
}
All is projected as you asked. Or not?
It works when using a json format. All fields that were specified in the Project parameter, returned properly.
Thank you for your support. I appreciate it.
I specified the project field as follow:
And this is the output:
This is the json format in the database:
How I can get that 'Agent.AgentDevice.AgentId' data?