我正在尝试删除数组中的对象。但是该数组嵌套在两个对象中。我该怎么做?
例如:让我们说要删除交易 _id:58c3154a19f82c0ddc53f0de
我该怎么做?
{
"_id": {
"$oid": "58bad6cf93ab9703da331e25"
},
"username": "david.lam@transfast.com",
"password": "sha1$fc05ad7d$1$1cc86a287642516f947fda520ae8ddd42e983e23",
"firstName": "David",
"lastName": "David",
"transactions": {
"2017": {
"3": [
{
"where": "Duane Reade",
"what": "asdf",
"category": 6,
"amount": "34",
"_id": {
"$oid": "58c300ef1602f90c7166cbfb"
},
"date": {
"day": 10,
"month": 3,
"year": 2017
}
},
{
"where": "Amazon",
"what": "asdf",
"category": 2,
"amount": "100",
"_id": {
"$oid": "58c3154a19f82c0ddc53f0de"
},
"date": {
"day": 10,
"month": 3,
"year": 2017
}
}
]
}
}
}
答案 0 :(得分:0)
为此,您需要使用$pull运算符。使用点表示法对数组元素进行寻址。以下查询完成了这项工作:
@echo off
setlocal
:: Initialize unit translation
for /f "eol== delims==" %%V in ('set unit_ 2^>nul') do set "%%V="
for %%A in ("t=TB" "g=GB" "m=MB" "k=KB") do set "unit_%%~A"
> filecount.TXT (
echo DATE: %DATE%
echo TIME: %TIME%
echo USER: %USERNAME%
echo COMPUTER: %COMPUTERNAME%
echo(
echo(
echo(
for /f "tokens=1" %%S in (servers.txt) do (
echo %%S :::
echo Counting %%S
call :printSize "\\%%S\c$\folder1\folder2"
echo(
echo(
)
)
exit /b
:printSize %1
setlocal
for /f "tokens=1,3,4" %%A in (
'robocopy %1 %1 /l /is /nfl /ndl /njh'
) do (
setlocal enableDelayedExpansion
if %%A == Files (
set "files= %%B"
) else if %%A == Bytes (
set "bytes= %%B"
set "unit=!unit_%%C!"
if not defined unit set "unit=B"
)
)
echo %files:~-16% File(s) %bytes:~-8% %unit%
exit /b