Reputation: 1067
I'm new in MeteorJS so this question might be dumb, but anyway. I've tried several times to follow tutorials about building a beginner's app with meteorJS, even the one provided at the front page of meteor.com . But this line of code
Something = new Meteor.Collection("something");
does not seem to work by the time a)my meteor app runs but finds (and returns) no data from this mongodb collection and b)when I type into the meteor app directory "meteor mongo"
and I try to manually insert some data into this collection, it returns me an undefined collection error.
I've installed MeteorJS just by using curl https://install.meteor.com/ | sh
, which as I know installs also a meteor-mongodb version.
After many hours of googling, I can admit that apparently I'm doing something wrong, but I cannot find out what! Any advice/help here would be highly appreciated!
Thank you in advance!
Upvotes: 0
Views: 94
Reputation: 5472
The simple example on meteor homepage uses two default packages called autopublish
and insecure
which allow you to quickly mock up applications that set publish/subscribe patterns for you behind the scenes and assume that visitors are trusted.
That being said, as soon as you set up your collection using:
CollectionNameMeteor = new Meteor.Collection("collection-name-mongo");
Meteor implements http://docs.meteor.com/#meteor_collection which is a mongodb compliant representation of your collection but the syntax is a little bit different.
While a direct query on mongodb with mongodb's syntax db.collection-name-mongo.find()
returns a document, meteor's collection api uses a slightly different syntax CollectionNameMeteor.find()
and returns a cursor as described here http://docs.meteor.com/#meteor_collection_cursor and to retrieve the document from that cursor, you need to CollectionNameMeteor.find().fetch()
which fetches the result as an array.
But you would normally use the cursor reference on your meteor code since most of meteor's magic relies on that.
Similarly, to do an insert, on the mongodb shell you'd do
db.collection-name-mongo.insert({foo: "bar"})
Whereas on meteor, you'd do
CollectionNameMeteor.insert({foo: "bar"})
Which also has a useful callback http://docs.meteor.com/#insert
Upvotes: 1