Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_ensureIndex causes crash #26

Open
cunneen opened this issue Jan 5, 2018 · 2 comments
Open

_ensureIndex causes crash #26

cunneen opened this issue Jan 5, 2018 · 2 comments

Comments

@cunneen
Copy link

cunneen commented Jan 5, 2018

If the collection I'm stubbing has a call to _ensureIndex (as per How to optimize your Mongo database for Meteor.js , I get the following error

Uncaught Error: Can only call _ensureIndex on server collections

at Mongo.Collection._ensureIndex (packages/mongo/collection.js:651:11)
at Object.invoke (.meteor/packages/hwillson_stub-collections/.1.0.6.1i286aa.gv4e++os+web.browser+web.cordova/npm/node_modules/sinon/lib/sinon/behavior.js:150:32)
at Mongo.Collection.functionStub (.meteor/packages/hwillson_stub-collections/.1.0.6.1i286aa.gv4e++os+web.browser+web.cordova/npm/node_modules/sinon/lib/sinon/stub.js:98:47)
at Function.invoke (.meteor/packages/hwillson_stub-collections/.1.0.6.1i286aa.gv4e++os+web.browser+web.cordova/npm/node_modules/sinon/lib/sinon/spy.js:193:47)
at Mongo.Collection.proxy [as _ensureIndex] (.meteor/packages/hwillson_stub-collections/.1.0.6.1i286aa.gv4e++os+web.browser+web.cordova/npm/node_modules/sinon/lib/sinon/spy.js:73:57)
@evg1n
Copy link

evg1n commented Nov 14, 2019

Hello,

I had the same issue, you should check whether you invoke this function on the server or on the client side. It must be invoked on the server side.

Meteor.startup( () => {
  SomeCollection._ensureIndex({
    "_id": 1
  });

  SomeCollectionTwo._ensureIndex({
    "_id": 1
  });
});

this is my perfectly working collectionIndex.js file, it is under
../imports/startup/server/collectionIndexes/ folder.

I hope this helps.

Cheers.

@cunneen
Copy link
Author

cunneen commented Nov 15, 2019

Thanks! I've actually no recollection of posting the above issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants