Can you please provide the full error trace? Any error message in the server console?
This what I got:
In the browser:
When I press the ‘Save’ button (above) in theory it should insert the information into the collection but instead I get this error (bellow).
I decided to look into Mongo to see if it would tell me something, but nothing (at least I think so)
.Please let me know if you need more information, I would be more than happy to provide (just be specific). I really need to find a solution to this, in order to finish this project. Please and once again, thank you in advance.
I apologize for the multiple reply posts; meteor only lets me post a image per post.
The most likely cause of this is that you have defined your collection (Test
) on the client only. Is the js code you originally provided in a file in the client/
folder?
Hey, Robfallows
Yes, it is. Do I have to create a serve folder and place the .js file with the collection in there?
Where exactly should I place it? Thank you
As your code is written (using Meteor.isServer
and Meteor.isClient
) you can if you wish place this in a shared location. In any event, the Test = new Mongo.Collection('test');
must be shared (the “usual” place is in lib/
).
By all means split your code appropriately between lib/
, client/
and server/
. There are some good patterns for this: look first in the “Organizing Your Project” section of the docs. If you put your code in these directories you can generally dispense with using Meteor.isServer
and Meteor.isClient
in your code.
Thank you so much, I did that and it worked! I really appreciate it.
Folders are very important in Meteor, not only for functionalities but also (and mostly) for security.
Here is the part of the manual describing how it works:
http://docs.meteor.com/#/full/structuringyourapp
May I highly recommend you to read at least the “Concepts” part of this manual. Not reading this will expose your code to the most basic security flaws and you won’t get how Meteor actually works until then.
Hi everyone, I am new to meteor.while do practice I have got a problem…
I Unable to insert data from browser.
This is my main.js file
and data in mongodb
But In browser the data is not displaying…
please help me to resolve this issue.Thanks a ton.
From what you’ve said it looks like you have not defined the collection on the server as well as on the client.
As you are using the 1.3 import
syntax, here’s what I would do:
Create a new file /imports/api/Names.js
and add the following into that file (note I used the Mongo.Collection
syntax - Meteor.Collection
has been deprecated for a couple of years):
export const Names = new Mongo.Collection('names');
In your client/main.js
remove Names = new Meteor.Collection('names');
and add
import { Names } from '/imports/api/Names';
to the import statements at the top.
Add the same import statement to the top of your server/main.js
file. This ensures the collection is defined on the server as well.
A final comment: if you are basing this off the initial “Welcome to Meteor” app which is created for you with meteor create ...
, your code is already split into client-only (under client/
) and server-only (under server/
)parts. Code in client/
does not need if (Meteor.isClient)
- it alway is client. Similarly if (Meteor.isServer)
code should be removed - it will never be executed. Code in server/
obeys similar rules: Meteor.isServer
is always true and Meteor.isClient
code can be removed.
A final, final comment (): you can paste your code between lines with triple backticks to get formatting and syntax highlighting:
```
paste code between backticks like this
```
Well, I have encountered a similar problem with the last one. Your answer just solved my problem. Thank you!
For some reason when I try to insert something into the collection it says:
insert failed: Access denied
Why?
Here’s my code and file structure:
Thank you!!!
You’re not importing ‘Posts’ from the code you show below.
When you create the mongo collection, and give it the ‘Posts’ handle, you need to import that into your script for that template.
import { Posts } from './servermain.js'
on the client in your template posts js file.
Updating meteor Packages solved my problem
Try to do so