Insert works but find and fetch doesnot return anything

We can’t see your template properly. Please edit your post and put a line with 3 backticks at the top of your template, and another line the same at the bottom:

```
your
template
here
```

check now, is it ok.

What does your Post.js file look like?

import {Mongo} from ‘meteor/mongo’; – not needed but I added anyhow :slight_smile:
so just this one line:

Post = new Mongo.Collection(‘post’);

Try export const Post = new Mongo.Collection('post');

1 Like

Oh! Thank you very much :slight_smile: It worked.

1 Like

Thanks for your advice to head up to leveluptuts :slight_smile:

Oh no, I was too soon to rejoice. What it displayed was the content I inserted before I added “export const” in the Post.js file.

Now when I try again to insert the console displays following error:

Now what?

So, you need to import { Post } from '/path/to/Post.js'; at the top of every file where you reference Post. You don’t need to do that if you don’t reference Post in a file.

You did not say where you have put Post.js. What is the “path/to/”?

Alright, whats happening is the content displayed was the inserts I have done on server.
But when I try to insert content from console the above error is thrown. I wanted insert from console.

And post.js file was in ‘…/lib/post.js’; which I included everywhere.

OK, so that will be automatically loaded in client and server. You don’t need imports (or the export) at all - in fact they may be causing problems - it’s not a combination I’ve ever tried! It sounds like the tutorial is using an old version of Meteor.

What may be happening here is that Post is not being attached to the global window object - so is not available in a console window outside of where it’s being used in the code.

To test that, modify your client/main.js to include window.Post = Post;. That should let you use it directly from the console.

1 Like

phooh! That worked! Thank you.

1 Like

Glad you got there in the end!

Maybe you should take a look at the official Meteor tutorials for a more modern approach :slight_smile:

2 Likes