更新并检索更新的文档mongodb

时间:2019-02-18 22:37:44

标签: mongodb mongoose

我正在尝试使用嵌套的子文档来更新文档,但是我总是检索以前的文档。

我尝试过

  

{returnOriginal:false}

但是它不起作用...

这是我在nodejs中的代码

almacenCtrl.updateAlmacen = async (req, res) => {
    almacen = await almacenModel.findOneAndUpdate(req.params.id, { $set: req.body }, { returnOriginal: false }, function (err, updated) {
        res.json(updated)
    })
}

我在做什么错了?

///更新后,我检查了mongoshell并成功更新了

1 个答案:

答案 0 :(得分:2)

使用CCTVCamera,如下所示:

Public Sub DoTranspose()
    Dim objValues As Scripting.Dictionary, objSrcCells As Range, objCell As Range
    Dim strKey As String, strValue As String, arrValues() As String, varKey As Variant
    Dim lngWriteRow As Long, lngWriteCol As Long, i As Long, objDestSheet As Worksheet

    Set objValues = New Scripting.Dictionary

    ' Use a new sheet called "Output" for the results.
    Set objDestSheet = Sheets("Output")

    ' Simply use the selected set of cells as the data for the transposition.
    Set objSrcCells = Selection

    For Each objCell In objSrcCells
        strValue = objCell.Value
        strKey = UCase(Left(strValue, Len(strValue) - 3))

        If Not objValues.Exists(strKey) Then
            ' The key doesn't exist, therefore, add it and add the first value.
            ReDim arrValues(0)
            arrValues(0) = strValue

            objValues.Add strKey, arrValues
        Else
            ' The key exists, append to the values array.
            arrValues = objValues.Item(strKey)

            ReDim Preserve arrValues(UBound(arrValues) + 1)
            arrValues(UBound(arrValues)) = strValue

            objValues.Item(strKey) = arrValues
        End If
    Next

    lngWriteCol = 0

    objDestSheet.Cells.Clear

    ' Write the results of the dictionary out to the destination sheet.
    For Each varKey In objValues.Keys
        lngWriteRow = 0
        lngWriteCol = lngWriteCol + 1

        arrValues = objValues.Item(varKey)

        For i = 0 To UBound(arrValues)
            lngWriteRow = lngWriteRow + 1
            objDestSheet.Cells(lngWriteRow, lngWriteCol) = arrValues(i)
        Next            
    Next

    objDestSheet.Columns.AutoFit
End Sub