Azure / azure-cosmosdb-js-server

The JavaScript SDK for server-side programming in Azure Cosmos DB
MIT License
178 stars 154 forks source link

__.replaceDocument always fails #26

Closed thomaslevesque closed 6 years ago

thomaslevesque commented 6 years ago

I have tried about every possible variation of this:

function test(id) {
    var collection = getContext().getCollection();

    var result = __.filter(
        function(doc) {
            return doc.id == id;
        },
        function (err, feed, options) {
            if (err) throw err;
            if (!feed || !feed.length) throw new Error("Not found");
            var doc = feed[0];
            doc.name = "foo";
            var result1 = __.replaceDocument(doc._self, doc, options, function (err1) {
                if (err1) throw err1;
            });
            if (!result1.isAccepted) throw new Error("replaceDocument was not accepted");
        });
    if (!result.isAccepted) throw new Error("filter was not accepted");
}

But whatever I do, I'm always getting "replaceDocument was not accepted". What am I doing wrong? Why does replaceDocument always fail?

thomaslevesque commented 6 years ago

OK, dumb mistake. I had not realized that replaceDocument returned a boolean, not a QueryResponse. Thanks, Javascript, for making me lose 2 hours of my life... a proper language with strong typing would have shown me the error immediately.