'Why MongoDB saves Hash value in different format?

I am learning IPFS and trying to save IPFS file info in MongoDB. After uploading, I get one hash value

ex: {fileHash: CID(QmbCaWPi9tSqcnykvBUMaH2M1d5PiVPLEfPwhJksSSeMak)}

And in MongoDB, I see something like this:

"fileHash": {
    "code": 112,
    "version": 0,
        "multihash": {
            "code": 18,
             "size": 32,
             "digest": "vxaISoMOXTpFy9rwnYilyk7pa6TlhkFDCZgcjGhXfm0=",
             "bytes": "EiC/FohKgw5dOkXL2vCdiKXKTulrpOWGQUMJmByMaFd+bQ=="
       },
    "bytes": "EiC/FohKgw5dOkXL2vCdiKXKTulrpOWGQUMJmByMaFd+bQ=="
}

Now I want to update this document based on hash value but don't understand what value I compare in match.

 db.collection("test").update(filter, set);

I was trying like this:

db.collection("test").update({fileHash:"CID(QmbCaWPi9tSqcnykvBUMaH2M1d5PiVPLEfPwhJksSSeMak)"}, set);

But it doesn't work



Solution 1:[1]

I think CID() is like a function.

When you use CID("QmbCaWPi9tSqcnykvBUMaH2M1d5PiVPLEfPwhJksSSeMak"), it come up with a JSON.

{
    "code": 112,
    "version": 0,
        "multihash": {
            "code": 18,
             "size": 32,
             "digest": "vxaISoMOXTpFy9rwnYilyk7pa6TlhkFDCZgcjGhXfm0=",
             "bytes": "EiC/FohKgw5dOkXL2vCdiKXKTulrpOWGQUMJmByMaFd+bQ=="
       },
    "bytes": "EiC/FohKgw5dOkXL2vCdiKXKTulrpOWGQUMJmByMaFd+bQ=="
}

So you should try something like

let fileHash = CID("QmbCaWPi9tSqcnykvBUMaH2M1d5PiVPLEfPwhJksSSeMak");
db.collection("test").update({fileHash: fileHash }, set);

Solution 2:[2]

Take that CID and use the method toString() on it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 YuTing
Solution 2 Nullable