在meteor项目中,我是否需要在此示例中导入{Meteor}
,{Mongo}
和{check}
?为什么呢?
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'}`)
}
}
})