0

First, I'm sorry I don't have more to describe this, but its some sort of obscure Meteor 1.2 bug. At least for me, since I am new.

Basically I am creating a one page intranet app that polls paysimple.com API, stores the results in MongoDB and lets Meteor use its reactive magic to push the new results to the page.

At first I thought this was related to this question: Meteor, '/users/insert' is already defined

Because I was using the word "Transactions" and thought I hit a keyword, but I rewrote the code to use the word "Payments".

Here is the error

W20150928-18:57:59.477(-7)? (STDERR)
W20150928-18:57:59.478(-7)? (STDERR) /Users/robert/.meteor/packages/meteor-tool/.1.1.8.1ywvo10++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150928-18:57:59.478(-7)? (STDERR)                        throw(ex);
W20150928-18:57:59.478(-7)? (STDERR)                              ^
W20150928-18:57:59.548(-7)? (STDERR) Error: A method named '/payments/insert' is already defined
W20150928-18:57:59.548(-7)? (STDERR)     at livedata_server.js:1536:15
W20150928-18:57:59.548(-7)? (STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
W20150928-18:57:59.548(-7)? (STDERR)     at [object Object]._.extend.methods (livedata_server.js:1532:7)
W20150928-18:57:59.548(-7)? (STDERR)     at [object Object].Mongo.Collection._defineMutationMethods (packages/mongo/collection.js:923:1)
W20150928-18:57:59.549(-7)? (STDERR)     at new Mongo.Collection (packages/mongo/collection.js:214:1)
W20150928-18:57:59.549(-7)? (STDERR)     at components/App.jsx:3:17
W20150928-18:57:59.549(-7)? (STDERR)     at /Users/robert/dev/paysimple-meteor/.meteor/local/build/programs/server/app/components/App.jsx:66:4
W20150928-18:57:59.549(-7)? (STDERR)     at /Users/robert/dev/paysimple-meteor/.meteor/local/build/programs/server/boot.js:242:10
W20150928-18:57:59.549(-7)? (STDERR)     at Array.forEach (native)
W20150928-18:57:59.549(-7)? (STDERR)     at Function._.each._.forEach (/Users/robert/.meteor/packages/meteor-tool/.1.1.8.1ywvo10++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)

The project is here on github: https://github.com/rbaindourov/paysimple-meteor

Community
  • 1
  • 1

2 Answers2

0

From looking at the error message it sounds as if you instantiate the same Collection more than ones. Or maybe define a server side method that interferes with the collection manipulating methods.

I have looked into your code, but unfortunately I cannot call the external API (I have no and can't get a Paysimple account - US residents only), and therefor can't really reproduce the behaviour.

When I simply insert something into Payments in the server code (init.js) I don't get the error.

I issued a get request to an arbitrary page and was able to store the result into the same collection, without an error.

At first your:

Payments.update( {Id:item.Id}, {$set:item}, {upsert:true} );

looked a little bit foreign to me, but I have tested it, and it worked as expected. I would have done:

Payments.upsert({Id: item.Id}, item);

My final guess is, from looking at your run script, that this might have to do with the Mongo instance you are running the app against.

I would try to remove the external MongoDB and run the app with the integrated one. Simply omit the MONGO_URL env variable declaration.

Good luck.

Crenshinibon
  • 187
  • 1
  • 5
0

The bug did go away by itself! Sort of.

Crenshinibon, you are right that I did have multiple declarations of the collection, once in server/init.js and once in components/App.jsx at one point.

But when I refactored the code to have a /lib/collections.js the error still persisted. This was the main problem that all my hunches kept getting invalided by meteor caching.

It wasn't until I renamed Task.jsx to LineItem.jsx and reflected that change throughout the application that the error just went away.

Which confirmed that there is a caching mechanism of some sorts that kept my bug hanging around, which was solved by some previous refactoring.

Therefore, I don't know exactly what change cleared the error, changing the collection name, or moving its declaration to one global lib file.

I've informed the meteor team here: https://forums.meteor.com/t/meteor-clear-cache/10507

They seem to agree that it's an issue.

Thanks again everyone, and I apologize for not committing the error before I fixed it. I was frantically writing code, and it just disappeared.