Mongo Document.find({})在router.js中返回undefined(使用Meteor与React,FlowRouter和React-Mounter)

时间:2018-03-01 14:42:43

标签: javascript mongodb reactjs meteor flow-router

我正在建立一个博客作为个人项目,目前我正在尝试建立RESTful路线,或多或少。具体来说,我试图在新路线中呈现完整的博客(在用户从主页面的列表中点击它之后)。

我被卡住了,因为当我尝试Blogs.find({...}).fetch()时,它不会返回可用的Blog对象。

当前router.js:

// Imports and two other routes above this

FlowRouter.route('/blogs/:postId', {
    name: 'Show.Blog',
    action(params, queryParams) {
        const theId = params.postId;
        console.log(theId);
        const blog = Blogs.find({
            "_id": "tbJ9aesG99u2rRyYP",
        });
        console.log(blog)
        mount(Appshell, {
            content: <FullBlog key={blog._id} blog={blog}/>
        });
    }
})

结果控制台打印:

Object { collection: {…}, sorter: null, matcher: {…}, _selectorId: "tbJ9aesG99u2rRyYP", skip: 0, limit: undefined, fields: undefined, _projectionFn: _compileProjection(), _transform: null, reactive: true }

我试图接受并添加:

const blog = Blogs.find({
        "_id": "tbJ9aesG99u2rRyYP",
    }).collection._docs._map;

将其缩小为:

    {}
​        PeRTpg7FuHhLeL59o: 
            Object { _id: "PeRTpg7FuHhLeL59o", title: "On Sleep", body: "//displays the body, it's pretty long", … }
​
RPZzFov3t9L54tMT3: Object { _id: "RPZzFov3t9L54tMT3", title: "On Half-Finished Poems", body: "//displays the body, it's pretty long", … }
​
RQEtvFt3sHcspjprE: Object { _id: "RQEtvFt3sHcspjprE", title: "", body: "//displays the body, it's pretty long", … }
​
rnoZwAyb3zExdhLaL: Object { _id: "rnoZwAyb3zExdhLaL", title: "", body: "//displays the body, it's pretty long", … }
​
tbJ9aesG99u2rRyYP: Object { _id: "tbJ9aesG99u2rRyYP", title: "On and On and On", body: "//displays the body, it's pretty long", … }
​
__proto__: Object { … }

所以我知道它能够找到我的数据,我似乎无法通过通常的Docs.find({})获得它。

我做错了什么?

My repo on GitHub。分支是~~'aadd-mongo'~~编辑:'add-mongo'。)

编辑:如果我将其更改为

const blog = Blogs.findOne({
    "_id": "tbJ9aesG99u2rRyYP",
});

console.log(blog)打印undefined

编辑:这个问题与我遇到的问题类似。 https://stackoverflow.com/a/31357970/7903932

0 个答案:

没有答案