MongoDB 缝合“入门”失败

jpm*_*yob 0 mongodb mongodb-stitch

没有什么比在简单的任务上失败更令人沮丧的了。

我正在关注:https : //docs.mongodb.com/stitch/getting-started/first-stitch-app/ - 我得到了 setp 9 - 这应该清除权限规则,所以任何人都可以查看我的职位;但是,我仍然收到权限错误。

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

这是整个代码 - 但我怀疑错误出在针迹设置方面。是的 - 我已经用我的应用程序 ID 替换了“your-app-id”...我确实清除了过滤器,并且我确实将 READ 权限更改为 {}...

<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>
Run Code Online (Sandbox Code Playgroud)

如果第一个真正的步骤失败,就不能再进一步了。任何帮助表示赞赏。

Nan*_*ndi 5

转到mongodb-atlasStitch控制台和交叉检查,如果你有一个名为集合blog.comments。这不是权限错误,很可能是由于缺少集合算法。

我尝试设置针迹一次,但遇到了同样的问题。只需确定是否<databasename>.<collectionname>与您在脚本中使用的内容相匹配,这里应该是blog.comments. 或者只是尝试从那里删除集合并创建一个新集合。

在此处输入图片说明