skip to Main Content

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

2

Answers


  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);
    
    Login or Signup to reply.
  2. Take that CID and use the method toString() on it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search