Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Meteor complain that an insert method for a collection is already defined?

Can anyone tell me why the code below throws the following error? :

Error: A method named '/players/insert' is already defined 

I'm new to Meteor and coffeescript so I may be overlooking something simple.

Here's my port of the leaderboard example to coffeescript:

###
Set up a collection to contain player information. On the server,
it is backed by a MongoDB collection named "players."
###
Players = new Meteor.Collection("players")

if Meteor.is_client
  Template.leaderboard.players = ->
    Players.find({}, {sort: {score: -1, name: 1}})

  Template.leaderboard.selected_name = ->
    player = Players.findOne(Session.get "selected_player")
    player and player.name

  Template.player.selected = -> if Session.equals("selected_player", this._id) then "selected" else ''

  Template.leaderboard.events = {
    'click input.inc': ->
      Players.update(Session.get("selected_player"), {$inc: {score: 5}})
  }

  Template.player.events = {
    'click': ->
      Session.set("selected_player", this._id)
  }

# On server startup, create some players if the database is empty.
if Meteor.is_server
  Meteor.startup ->
    if Players.find().count() is 0
      names = [
                "Ada Lovelace"
                "Grace Hopper"
                "Marie Curie"
                "Carl Friedrich Gauss"
                "Nikola Tesla"
                "Claude Shannon"
              ]
      Players.insert({name: name, score: Math.floor(Math.random()*10)*5}) for name in names

The full stack trace is as follows:

[[[[[ ~/dev/meteor/leaderboard ]]]]]

Running on: http://localhost:3000/

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: A method named '/players/insert' is already defined
    at app/packages/livedata/livedata_server.js:744:15
    at Function.<anonymous> (app/packages/underscore/underscore.js:84:24)
    at [object Object].methods (app/packages/livedata/livedata_server.js:742:7)
    at new <anonymous> (app/packages/mongo-livedata/collection.js:111:13)
    at app/leaderboard.js:4:11
    at /Users/alex/dev/meteor/leaderboard/.meteor/local/build/server/server.js:109:21
    at Array.forEach (native)
    at Function.<anonymous> (/Users/alex/dev/meteor/leaderboard/.meteor/local/build/server/underscore.js:76:11)
    at /Users/alex/dev/meteor/leaderboard/.meteor/local/build/server/server.js:95:7
Exited with code: 1

I'm running Meteor version 0.4.0 (8f4045c1b9)

Thanks in advance for assistance!

like image 418
AlexEberts Avatar asked Sep 20 '12 23:09

AlexEberts


1 Answers

You would also get this error, regardless of using coffeescript or plain javascript, if you duplicated your files. For example, copying your sources files to a subdirectory named Backup would produce this error, because Meteor merges files from subdirectories.

like image 140
Gwened Avatar answered Nov 16 '22 02:11

Gwened