Why does Meteor complain that the insertion method for the collection is already defined?

Can someone tell me why the code below is causing the following error?

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

I am new to Meteor and coffeescript, so I can skip something simple.

Here is my leader example port for 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 

A 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 am running Meteor version 0.4.0 (8f4045c1b9)

Thanks in advance for your help!

+7
source share
3 answers

You will also get this error, regardless of using coffeescript or plain javascript if you duplicate your files. For example, copying source files to a subdirectory called Backup will result in this error because Meteor merges files from subdirectories.

+12
source

This is a configuration issue with coffeelint (installed globally with npm).

I initially installed coffeelint to verify that my coffeescript code was correct and that there were no errors.

I installed coffeelint as instructed using:

sudo npm install -g coffeelint

coffeelint worked great when it worked offline with files. coffee.

However, when starting any Meteor project with coffeescript package, I got the above error.

On a whim, I thought the error might be due to a conflict with my existing node installation.

I decided to remove coffeelint first:

sudo npm uninstall -g coffeelint

and then deleted the leaderboard.js file previously created by the meteorite.

After restarting the meteor, the coffeescript example above worked as expected without errors.

0
source

try moving (i.e. copying and deleting the original)

Players = new Meteor.Collection("players")

once below if Meteor.is_client and at another time below if Meteor.is_server

I don’t know exactly why, since I am new to Meteor, but it worked for me, I believe that the server side needs its own link, as well as the client, although an announcement outside the scope should do the same (maybe an error, remember that they are still on preview 0.5.0, which makes me think that you can upgrade and try new smart packages with the new version, it looks like you are using 0.4), but when the files on my server are not find out nothing, I defined the root directory of the meteor (which nudges flushes these files to the client and server), I have defined their own server link, and I got the same error, and until I moved the "public" declaration of links to provide the server and client to each their own copy, nothing happened.

Hope this helps ...

0
source

All Articles