Mongo Document.find({}) returning undefined in router.js (using Meteor with React, FlowRouter and React-Mounter)

105 Views Asked by At

I'm building a blog as a personal project, and currently I'm trying to set up RESTful routes, more or less. Specifically, I am trying to render a full Blog in a new route (after a user clicks on it in a list from the main page).

I'm stuck because when I try and Blogs.find({...}).fetch() it doesn't return a usable Blog object.

Current 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}/>
        });
    }
})

Resulting console prints:

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

I tried to take that and add:

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

Which narrows it down to:

    {}
​        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 { … }

So I know it is capable of finding my data, I just can't seem to get it through the usual Docs.find({}).

What am I doing wrong?

(My repo on GitHub. The branch is ~~'aadd-mongo'~~ edit: 'add-mongo'.)

Edit: If I change it to

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

console.log(blog) prints undefined.

Edit: This question seems similar to what I'm experiencing. https://stackoverflow.com/a/31357970/7903932

0

There are 0 best solutions below