jamauro / offline

An easy way to give your Meteor app offline capabilities and make it feel instant
11 stars 1 forks source link

Error: Can only call createIndexAsync on server collections #3

Closed StorytellerCZ closed 1 month ago

StorytellerCZ commented 1 month ago

Given the code:

import { Mongo } from 'meteor/mongo'

export const BookmarkChapterCollection = new Mongo.Collection('bookmarkChapter')

if (Meteor.isServer) {
  BookmarkChapterCollection.createIndexAsync({
    userId: 1,
    storyId: 1,
    language: 1,
  })
  BookmarkChapterCollection.createIndexAsync(
    { userId: 1, storyId: 1, chapterId: 1, language: 1 },
    { unique: true },
  )
}

I get the following error

W20240725-15:47:50.209(2)? (STDERR) meteor://💻app/packages/mongo.js:4730
W20240725-15:47:50.210(2)? (STDERR)         if (!self._collection.createIndexAsync) throw new Error('Can only call createIndexAsync on server collections');
W20240725-15:47:50.210(2)? (STDERR)                                                       ^
W20240725-15:47:50.210(2)? (STDERR) 
W20240725-15:47:50.211(2)? (STDERR) Error: Can only call createIndexAsync on server collections
W20240725-15:47:50.211(2)? (STDERR)     at ns.Collection.createIndexAsync (packages/mongo/collection.js:1120:13)
W20240725-15:47:50.211(2)? (STDERR)     at module.wrapAsync.self (imports/api/collections/bookmarkChapter.ts:69:29)
W20240725-15:47:50.211(2)? (STDERR)     at Module.wrapAsync (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:251:8)
W20240725-15:47:50.212(2)? (STDERR)     at module (/home/storyteller/Web/Literary-Universe/app/.meteor/local/build/programs/server/app/app.js:872:9)
W20240725-15:47:50.212(2)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:335:7)
W20240725-15:47:50.212(2)? (STDERR)     at Module.require (packages/modules-runtime.js:237:14)
W20240725-15:47:50.212(2)? (STDERR)     at Module.mod.require (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:30:33)
W20240725-15:47:50.212(2)? (STDERR)     at Module.moduleLink [as link] (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:104:22)
W20240725-15:47:50.212(2)? (STDERR)     at module.wrapAsync.self (server/resolvers/stories.ts:1:46)
W20240725-15:47:50.212(2)? (STDERR)     at Module.wrapAsync (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:251:8)
W20240725-15:47:50.213(2)? (STDERR)     at module (/home/storyteller/Web/Literary-Universe/app/.meteor/local/build/programs/server/app/app.js:38375:9)
W20240725-15:47:50.213(2)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:335:7)
W20240725-15:47:50.213(2)? (STDERR)     at Module.require (packages/modules-runtime.js:237:14)
W20240725-15:47:50.213(2)? (STDERR)     at Module.mod.require (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:30:33)
W20240725-15:47:50.213(2)? (STDERR)     at Module.moduleLink [as link] (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:104:22)
W20240725-15:47:50.213(2)? (STDERR)     at module.wrapAsync.self (server/resolvers/index.ts:1:54)
W20240725-15:47:50.213(2)? (STDERR)     at Module.wrapAsync (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:251:8)
W20240725-15:47:50.214(2)? (STDERR)     at module (/home/storyteller/Web/Literary-Universe/app/.meteor/local/build/programs/server/app/app.js:36737:9)
W20240725-15:47:50.214(2)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:335:7)
W20240725-15:47:50.214(2)? (STDERR)     at Module.require (packages/modules-runtime.js:237:14)
W20240725-15:47:50.214(2)? (STDERR)     at Module.mod.require (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:30:33)
W20240725-15:47:50.214(2)? (STDERR)     at Module.moduleLink [as link] (/home/storyteller/.meteor/packages/modules/.0.20.1.q93lib.5y9zm++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:104:22)
W20240725-15:47:50.214(2)? (STDERR) 
W20240725-15:47:50.214(2)? (STDERR) Node.js v20.15.1

Similar thing happens with createIndex in Meteor 2.16.

jamauro commented 1 month ago

Thanks for reporting. I've published a new version v0.1.1 which I hope will fix this. I wasn't able to reproduce the error exactly but I believe I identified the issue.

Once you confirm it's fixed, we can close this.

StorytellerCZ commented 1 month ago

Testing out now!

StorytellerCZ commented 1 month ago

Fixed!