MongoDB stitch "getting started" failure

2.2k Views Asked by At

Nothing is more frustrating than failing on a simple task.

I am following along with : https://docs.mongodb.com/stitch/getting-started/first-stitch-app/ - and I get to setp 9 - which is supposed to clear the permissions rule, so anyone can view my posts; however, I still get the permissions error.

Uncaught (in promise) Error: no rule exists for namespace 'blog.comments'
at client.js:343
at <anonymous>

Here's the entire code - but I suspect the error is on the stitch setting side. YES - i have replaced "your-app-id" with my app id... I DID clear the filter, and I did change the READ permission to {}...

<html>
    <head>
        <script src="https://s3.amazonaws.com/stitch-sdks/js/library/v2/stable/stitch.min.js"></script>
        <script>
            const client = new stitch.StitchClient('<your-app-id>');
            const db = client.service('mongodb', 'mongodb-atlas').db('blog');

            function displayComments() {
                db.collection('comments').find({}).execute().then(docs => {
                var html = docs.map(c => '<div>' + c.comment + '</div>').join('');
                document.getElementById('comments').innerHTML = html;
                });
            }

            function displayCommentsOnLoad() {
                client.login().then(displayComments)
            }

            function addComment() {
                var c = document.getElementById('new_comment');
                db.collection('comments').insertOne({owner_id : client.authedId(), comment: c.value})
                .then(displayComments);
                c.value = '';
            }
        </script>
    </head>
    <body onload="displayCommentsOnLoad()">
        <h3>Aspirational blog post</h3>
        <div id="content">
            I like to write about technology, because I want to get on the front page of hacker news (in a good way).
        </div>

        <hr>
        <div id="comments"></div>

        <hr>
        Add comment:
        <input id="new_comment"><input type="submit" onClick="addComment()">
    </body>
</html>

Cant go any further, if the first real steps fail. ANY help is appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

Go to mongodb-atlas in the Stitch console and cross check if you have a collection named blog.comments. It's not the permission error, it's most likely due to the absence of the collection algogether.

I tried setting up stitch once and got into the same problem. Just make sure if the <databasename>.<collectionname> is matching with what you are using in your script which here should be blog.comments. Or just try deleting the collection from there and create a new one.

enter image description here