user8599763
user8599763

Reputation: 13

Required imports for Meteor

In meteor project, do I need to import {Meteor},{Mongo}, and{check} in this example? Why?

collections.js

    // import {Mongo} from 'meteor/mongo' // ---- i have to import this?

    Bookmarks = new Mongo.Collection('bookmarks')

methods.js

    // import {check} from 'meteor/check' // ---- i have to import this?
    import {Bookmarks} from "/imports/schema/bookmarks/index"

    Meteor.methods({
     'bookmark.add'({name, url}){
      check(name,String) // ---------------
      check(url,String)

    const bookmarkId = Bookmarks.insert({name,url})
    Meteor.isServer && console.log(`Id ${bookmarkId} inserted`)
  },
  'bookmark.remove'(_id){
    check(_id,String)

    const bookmark = Bookmarks.findOne({_id})
    if (!bookmark){
      Meteor.isServer && console.log('no such a bookmark!')
    } else {
      const removeBookmarkId = Bookmarks.remove({_id})
      Meteor.isServer && console.log(`remove result ${removeBookmarkId?'success':'error'}`)
    }
  }
})

Upvotes: 1

Views: 35

Answers (1)

Derek Brown
Derek Brown

Reputation: 4419

The short answer is yes. Meteor makes heavy use of the module system for imports and exports. You can read more about how Meteor modules works, and the reasons motivating the move to Meteor modules here.

Upvotes: 2

Related Questions