These are chat archives for Automattic/mongoose

Mar 2018
Mar 08 2018 16:57

Hi there! I'm having a simple problem if anyone is interested in solving. So basically were trying to update a property in our schema that is kinda deeply nested.

module.exports.updateStoreToken = (uid, aid, storeObject, callback) => {

        _id: uid,
        "installed._id": aid,
        "installed.$.stores.endpoint": storeObject.endpoint
    }, {
            "installed.$.stores.$": storeObject
        }, { new: true }, callback)

Were wondering how to update a single store that has a property value equal to the variable storeObject.endpoint.

  • installed : Array
  • stores: Array

We got it working with 2 queries, one to unset and one to set. But were trying to do it with one query.

Juha Lindstedt
Mar 08 2018 17:01
Gosh this Gitter is unusable on mobile. I canā€™t scroll horizontally that code block at all šŸ˜•
You can use null to unset if that helps..?
Sorry I canā€™t see the whole code right now..
Mar 08 2018 18:23
@pakastin hmm but how could set to null and set to another value in the same query?
Mar 08 2018 22:00
how can I update or create a document through 1 operation, setting different property whether it's an update or a create (that's what makes upsert inappropriateĀ°?