MongoDB从Array in Object中的Array中的Object更新值

时间:2018-01-20 23:20:03

标签: arrays node.js mongodb object

我想更新价值。间隙应该与他的id和口袋里的id一起定位。 我尝试使用updateOne()函数,但我无法找到差距的路径。 也许你可以帮助我。

口袋和间隙阵列中会有更多物体。

{
    "_id":"5a4f535f4dc4b200d43cf333",
    "id":"A07","name":"name",
    "capacity":"230",
    "free":"230",
    "open":false,
    "location":
        {
            "longitude":51.02274,
            "latitude":7.5612
    },
    "pockets":
        [
            {
                "id":"A",
                "description":"Parktasche",
                "capacity":12,
                "free":11,
                "gaps":
                    [
                        {
                            "id":"7",
                            "value":true,      <-- should be updating
                            "deployee":false,
                            "disabled":false,
                            "guest":false,
                            "pid":"A"
                        }
                    ]
            }
        ]
    }

1 个答案:

答案 0 :(得分:0)

如果我没记错的话,你需要像unsigned int loadTexture(char const * path) { unsigned int textureID; glGenTextures(1, &textureID); int width, height, nrComponents; unsigned char *data = stbi_load(path, &width, &height, &nrComponents, 0); if (data) { GLenum format; if (nrComponents == 1) format = GL_RED; else if (nrComponents == 3) format = GL_RGB; else if (nrComponents == 4) format = GL_RGBA; glBindTexture(GL_TEXTURE_2D, textureID); glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, format == GL_RGBA ? GL_CLAMP_TO_EDGE : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, format == GL_RGBA ? GL_CLAMP_TO_EDGE : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); stbi_image_free(data); } else { std::cout << "Texture failed to load at path: " << path << std::endl; stbi_image_free(data); } return textureID }

这样的东西

https://docs.mongodb.com/manual/reference/operator/update/positional/#update-documents-in-an-array