0
votes

We have an existing mongodb which I imported into my Meteor app using:

mongorestore -h 127.0.0.1 --port 3001 -d meteor dump/mymongodb

Now it seems I can access any collection just find by using the collection name for example:

Meteor.publish 'works', ->
  Works.find({}, {limit: 10, sort: {createdAt: -1}})

Seems to work, as we had a collection named works. I didn't even have to define it:

@Works = new Meteor.collection('works') 

although it probably wouldn't hurt to define it.

But I am lost when it comes to the Meteor.users collection. We had a collection in our database called users, but I cannot access that one. How can I get our users collection from other mongodb into Meteor.users for the app?

PS. I can access the users collection directly from terminal using 'meteor mongo' and search db.users.findOne() but I cannot seem to access it from the code files.

1
Are you using any of the accounts packages (e.g. accounts-password)? - David Weldon
no i am not, should i be? - Nearpoint

1 Answers

1
votes

You need collections to be defined in order to use them. Meteor.users is defined by the accounts packages (e.g. accounts-password). If you are not using any of those packages, you will need to define the collection like so:

@Users = new Mongo.Collection 'users'

or

@Meteor.users = new Mongo.Collection 'users'

I regularly do this in apps which talk to our database but which don't require any user interaction (db migrations, stats reporting, etc.).

Of course, without the accounts packages installed, you get none of the other user functionality, but that may not matter in your case.