SimpleSchema is not a constructor - meteor

My app constantly crashes with this error. TypeError: SimpleSchema is not a constructor at attendances.js (imports/api/attendances/attendances.js:44:27). I've googled it and the StackOverflow solution doesn't work. I'm running simpl-schema and Collection2 Can anyone tell me whats wrong here?
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
const Attendances = new Mongo.Collection('attendances');
Attendances.debug = true;
Attendances.allow({
insert: () => true,
update: () => true,
remove: () => true,
});
Attendances.deny({
insert: () => false,
update: () => false,
remove: () => false,
});
const AttendancesSchema = new SimpleSchema({
createdAt: {
type: Date,
},
}, {
clean: {
filter: true,
autoConvert: true,
removeEmptyStrings: true,
trimStrings: true,
getAutoValues: true,
},
});
Attendances.attachSchema(AttendancesSchema);
export default Attendances;
This is the full error message in my terminal.
Path: ERROR MESSAGE
W20180620-21:07:11.542(10)? (STDERR) TypeError: SimpleSchema is not a constructor
W20180620-21:07:11.542(10)? (STDERR) at attendances.js (imports/api/attendances/attendances.js:44:27)
W20180620-21:07:11.543(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.543(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.543(10)? (STDERR) at publications.js (imports/api/userProfiles/server/publications.js:1:354)
W20180620-21:07:11.543(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.543(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.543(10)? (STDERR) at register-api.js (imports/startup/server/register-api.js:1:195)
W20180620-21:07:11.543(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.544(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.544(10)? (STDERR) at index.js (imports/startup/server/index.js:1:50)
W20180620-21:07:11.544(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.544(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.544(10)? (STDERR) at main.js (server/main.js:1:14)
W20180620-21:07:11.544(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.545(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.545(10)? (STDERR) at /Users/blakepascoe/Documents/dev/roll_call/.meteor/local/build/programs/server/app/app.js:1725:1

I tried the suggested fix in the comment by #bp123 that you should reset the Meteor project, and that fixed it for me too.
So I'm turning that comment into an answer:
Reset your project.
It does not seem impossible that a schema need to be added before any data is put in the database, but I'm very confused why this applies even for creating a Schema without attaching it to anything.

Related

Getting errors after install linux when i tried to open my vue 3 project

whenever i try to open any of my vue 3 project. I tried npm i autoprefixer but didn't work , then i tried deleting packagelock.json and node modules also it's not working, below are the errors I receive :
Compiled with problems:X
ERROR in ./src/router/index.js 4:0-51
Module not found: Error: Can't resolve '../views/AccountView.vue' in 'D:\project\Church\src\router'
ERROR in ./src/App.vue?vue&type=style&index=0&id=7ba5bd90&lang=css (./node_modules/css-loader/dist/cjs.js??clonedRuleSet-12.use[1]!./node_modules/vue-loader/dist/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-12.use[2]!./node_modules/vue-cli-plugin-quasar/lib/loader.vue.auto-import-quasar.js??ruleSet[0].use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[1]!./src/App.vue?vue&type=style&index=0&id=7ba5bd90&lang=css)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
Error: Cannot find module 'autoprefixer'
Require stack:
D:\project.postcssrc.js
D:\project\Church\node_modules\cosmiconfig\dist\loaders.js
D:\project\Church\node_modules\cosmiconfig\dist\ExplorerBase.js
D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js
D:\project\Church\node_modules\cosmiconfig\dist\index.js
D:\project\Church\node_modules\postcss-loader\dist\utils.js
D:\project\Church\node_modules\postcss-loader\dist\index.js
D:\project\Church\node_modules\postcss-loader\dist\cjs.js
D:\project\Church\node_modules\webpack\lib\ProgressPlugin.js
D:\project\Church\node_modules\progress-webpack-plugin\index.js
D:\project\Church\node_modules#vue\cli-service\lib\commands\serve.js
D:\project\Church\node_modules#vue\cli-service\lib\Service.js
D:\project\Church\node_modules#vue\cli-service\bin\vue-cli-service.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (D:\project.postcssrc.js:2:3)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at module.exports (D:\project\Church\node_modules\import-fresh\index.js:32:59)
at loadJs (D:\project\Church\node_modules\cosmiconfig\dist\loaders.js:16:18)
at Explorer.loadFileContent (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:84:32)
at Explorer.createCosmiconfigResult (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:89:36)
at Explorer.loadSearchPlace (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:70:31)
at async Explorer.searchDirectory (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:55:27)
at async run (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:35:22)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async Explorer.search (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:27:20)
at async loadConfig (D:\project\Church\node_modules\postcss-loader\dist\utils.js:68:16)
at async Object.loader (D:\project\Church\node_modules\postcss-loader\dist\index.js:54:22)
ERROR in ./node_modules/#quasar/extras/material-icons/material-icons.css (./node_modules/css-loader/dist/cjs.js??clonedRuleSet-14.use[1]!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-14.use[2]!./node_modules/#quasar/extras/material-icons/material-icons.css)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
Error: Cannot find module 'autoprefixer'
Require stack:
D:\project.postcssrc.js
D:\project\Church\node_modules\cosmiconfig\dist\loaders.js
D:\project\Church\node_modules\cosmiconfig\dist\ExplorerBase.js
D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js
D:\project\Church\node_modules\cosmiconfig\dist\index.js
D:\project\Church\node_modules\postcss-loader\dist\utils.js
D:\project\Church\node_modules\postcss-loader\dist\index.js
D:\project\Church\node_modules\postcss-loader\dist\cjs.js
D:\project\Church\node_modules\webpack\lib\ProgressPlugin.js
D:\project\Church\node_modules\progress-webpack-plugin\index.js
D:\project\Church\node_modules#vue\cli-service\lib\commands\serve.js
D:\project\Church\node_modules#vue\cli-service\lib\Service.js
D:\project\Church\node_modules#vue\cli-service\bin\vue-cli-service.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (D:\project.postcssrc.js:2:3)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at module.exports (D:\project\Church\node_modules\import-fresh\index.js:32:59)
at loadJs (D:\project\Church\node_modules\cosmiconfig\dist\loaders.js:16:18)
at Explorer.loadFileContent (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:84:32)
at Explorer.createCosmiconfigResult (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:89:36)
at Explorer.loadSearchPlace (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:70:31)
at async Explorer.searchDirectory (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:55:27)
at async run (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:35:22)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async Explorer.search (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:27:20)
at async loadConfig (D:\project\Church\node_modules\postcss-loader\dist\utils.js:68:16)
at async Object.loader (D:\project\Church\node_modules\postcss-loader\dist\index.js:54:22)
ERROR in ./src/styles/quasar.scss (./node_modules/css-loader/dist/cjs.js??clonedRuleSet-24.use[1]!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-24.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-24.use[3]!./node_modules/vue-cli-plugin-quasar/lib/loader.scss.js!./src/styles/quasar.scss)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
Error: Cannot find module 'autoprefixer'
Require stack:
D:\project.postcssrc.js
D:\project\Church\node_modules\cosmiconfig\dist\loaders.js
D:\project\Church\node_modules\cosmiconfig\dist\ExplorerBase.js
D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js
D:\project\Church\node_modules\cosmiconfig\dist\index.js
D:\project\Church\node_modules\postcss-loader\dist\utils.js
D:\project\Church\node_modules\postcss-loader\dist\index.js
D:\project\Church\node_modules\postcss-loader\dist\cjs.js
D:\project\Church\node_modules\webpack\lib\ProgressPlugin.js
D:\project\Church\node_modules\progress-webpack-plugin\index.js
D:\project\Church\node_modules#vue\cli-service\lib\commands\serve.js
D:\project\Church\node_modules#vue\cli-service\lib\Service.js
D:\project\Church\node_modules#vue\cli-service\bin\vue-cli-service.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (D:\project.postcssrc.js:2:3)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at module.exports (D:\project\Church\node_modules\import-fresh\index.js:32:59)
at loadJs (D:\project\Church\node_modules\cosmiconfig\dist\loaders.js:16:18)
at Explorer.loadFileContent (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:84:32)
at Explorer.createCosmiconfigResult (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:89:36)
at Explorer.loadSearchPlace (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:70:31)
at async Explorer.searchDirectory (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:55:27)
at async run (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:35:22)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async cacheWrapper (D:\project\Church\node_modules\cosmiconfig\dist\cacheWrapper.js:16:18)
at async Explorer.search (D:\project\Church\node_modules\cosmiconfig\dist\Explorer.js:27:20)
at async loadConfig (D:\project\Church\node_modules\postcss-loader\dist\utils.js:68:16)
at async Object.loader (D:\project\Church\node_modules\postcss-loader\dist\index.js:54:22)
You should run npm install -D autoprefixer and then make sure that the file src/router/views/AccountView.vue does exist. IF it does not exist there - you must update the pathname in src/router/index.js

why does the pinia getter mark an existing object as undefined?

I am trying to access one of the properties of a nested object in a pinia state called activeTicket but it always returns it as undefined but if it is full why could this be ?
export const useTicketStore = defineStore('ticketStore', () => {
const activeTicket = ref({});
const getCurrent = computed(() => {
const formatedCurrent = {
item :activeTicket.value.item,
tipo :activeTicket.value.type,
estado :activeTicket.value.status,
solicitante :activeTicket.value.sendBy.nickName,
fecha :activeTicket.value.createdAt
}
return formatedCurrent
});
return {
currentTicket: activeTicket,
getCurrent
}
});
when commenting on the line
// requester :activeTicket.value.sendBy.nickName,
the error disappears
this is the store
and this is the error i got
ticketStore.js?t=1662253680543:89 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'nickName')
at ReactiveEffect.fn (ticketStore.js?t=1662253680543:89:46)
at ReactiveEffect.run (reactivity.esm-bundler.js:185:25)
at get value [as value] (reactivity.esm-bundler.js:1144:39)
at Object.get2 [as get] (reactivity.esm-bundler.js:484:67)
at Proxy._sfc_render (TechHome.vue:5:34)
at renderComponentRoot (runtime-core.esm-bundler.js:896:44)
at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5580:57)
at ReactiveEffect.run (reactivity.esm-bundler.js:185:25)
at instance.update (runtime-core.esm-bundler.js:5694:56)
at setupRenderEffect (runtime-core.esm-bundler.js:5708:9)

"Request is not available" on apollo graphql query to withApiAuthRequired endpoint

I'm fairly new to graphql/apollo setup, and am stuck on the following issue:
My setup looks like this roughly:
Resolvers:
export const resolvers: Resolvers = {
Query: {
getUser: withApiAuthRequired(getUser)
}
};
async function getUser(req: any, res: any) {
try {
const { accessToken } = await getAccessToken(req, res);
console.log(accessToken);
} catch (error) {
console.error(error);
res.status(error.status || 500).end(error.message);
}
}
Client caller:
const data = await client.query({
query: gql`
query UsersQuery {
getUser
}
`
});
console.log(data);
The error I get:
Uncaught (in promise) Error: Request is not available
at new ApolloError (index.js?f0e4:29:1)
at eval (QueryManager.js?2692:596:1)
at both (asyncMap.js?bd9c:16:46)
at eval (asyncMap.js?bd9c:9:57)
at new Promise (<anonymous>)
at Object.then (asyncMap.js?bd9c:9:1)
at Object.eval [as next] (asyncMap.js?bd9c:17:1)
at notifySubscription (module.js?9653:132:1)
at onNotify (module.js?9653:176:1)
at SubscriptionObserver.next (module.js?9653:225:1)
at eval (iteration.js?aad9:4:50)
at Array.forEach (<anonymous>)
at iterateObserversSafely (iteration.js?aad9:4:1)
at Object.next (Concast.js?eb39:25:43)
at notifySubscription (module.js?9653:132:1)
at onNotify (module.js?9653:176:1)
at SubscriptionObserver.next (module.js?9653:225:1)
at eval (createHttpLink.js?2d67:103:1)
Thank you so much for the guidance!
try this one:
const data = await client.query({
query: gql `
query {
getUser
}
`
});
console.log(data);
I believe the issue is that I was trying to use withApiAuthRequired inside Resolvers. The argument to Resolvers needs to be an unwrapped function to work. I ended up just skipping the withApiAuthRequired wrapper and using getSession instead.

Socket hang up error in Cloud Functions for Firebase

I have a Cloud Function that is triggered by a Pub / Sub event. It uses request-promise to make multiple GET requests from an API I use for my data.
It works when running locally in the Cloud Functions Emulator, however in production I keep getting this error:
{ RequestError: Error: socket hang up
at new RequestError (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/user_code/node_modules/request/request.js:185:22)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.onRequestError (/user_code/node_modules/request/request.js:877:8)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketOnEnd (_http_client.js:346:9)
at emitNone (events.js:91:20)
at TLSSocket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
name: 'RequestError',
message: 'Error: socket hang up',
cause:
{ Error: socket hang up
at createHangUpError (_http_client.js:254:15)
at TLSSocket.socketOnEnd (_http_client.js:346:23)
at emitNone (events.js:91:20)
at TLSSocket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' },
error:
{ Error: socket hang up
at createHangUpError (_http_client.js:254:15)
at TLSSocket.socketOnEnd (_http_client.js:346:23)
at emitNone (events.js:91:20)
at TLSSocket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' },
options:
{ method: 'GET',
uri: 'https://api.coinmarketcap.com/v2/ticker/?convert=BTC&start=0',
json: true,
callback: [Function: RP$callback],
transform: undefined,
simple: true,
resolveWithFullResponse: false,
transform2xxOnly: false },
response: undefined }
Any idea why I get this socket hang up error when my Cloud Function runs?
Edit: Here is what my cloud function code looks like:
const functions = require('firebase-functions');
// Import Admin SDK
var admin = require("firebase-admin");
var reqprom = require('request-promise');
admin.initializeApp(functions.config().firebase);
exports.minutely_tick =
functions.pubsub.topic('minutely-tick').onPublish((event) => {
console.log('This job runs every 5 minutes!');
getAllData()
.then((dataArray) => {
const ref = admin.database().ref(`myData/`);
ref.set(dataArray);
return console.log('dataArray length:', dataArray.length);
})
.catch((error) => {
return console.log('Caught error: ', error);
});
});
function getAllData() {
return new Promise((resolve, reject) => {
var promises = [];
var startInt = 0;
for (i = 0; i < 1000; i++) {
const options = {
method: GET,
uri: myUrlString,
json: true
}
promises.push(reqprom(options));
startInt += 100;
}
Promise.all(promises)
.then((dict) => {
var array = valuesFromDict(dict);
return resolve(array);
})
.catch((error) => {
return reject(error);
});
});
}
function valuesFromDict(dict) {
var values = Object.keys(dict).map((key) => {
return dict[key];
});
return values;
}
In summary, the function makes multiple API calls in a loop. And via promises I wait for all of them to complete. And then format that data into an array that I set to a Firebase Database reference.
You're not returning the final promise from your promise chain. Cloud Functions requires that you return a promise that resolves only when all of the async work is complete in your function.
return getAllData().then(...).catch(...)
i had a content filter in my computer, when i removed it the problem solved

Looping Futures Exception. How to fix the cause

I'm working through the Discover Meteor book and after implementing the 'Errors' chapter, a typo caused an error an now the app is loop with the exception presented below.
My question is, how do I fix it or reset (I've tried 'meteor reset' but the exception loop persists)
W20140711-10:21:00.387(2)? (STDERR)
W20140711-10:21:00.388(2)? (STDERR) /Users/mwho/.meteor/tools/858c88b520/lib/node_modules/fibers/future.js:173
W20140711-10:21:00.390(2)? (STDERR) throw(ex);
W20140711-10:21:00.391(2)? (STDERR) ^
W20140711-10:21:00.479(2)? (STDERR) Error: allow: Invalid key: remote
W20140711-10:21:00.480(2)? (STDERR) at packages/mongo-livedata/collection.js:575
W20140711-10:21:00.492(2)? (STDERR) at Array.forEach (native)
W20140711-10:21:00.493(2)? (STDERR) at Function._.each._.forEach (packages/underscore/underscore.js:105)
W20140711-10:21:00.494(2)? (STDERR) at addValidator (packages/mongo-livedata/collection.js:573)
W20140711-10:21:00.496(2)? (STDERR) at Meteor.Collection.allow (packages/mongo-livedata/collection.js:613)
W20140711-10:21:00.496(2)? (STDERR) at app/collections/posts.js:3:7
W20140711-10:21:00.497(2)? (STDERR) at app/collections/posts.js:52:3
W20140711-10:21:00.498(2)? (STDERR) at /Users/mwho/microsope/.meteor/local/build/programs/server/boot.js:155:10
W20140711-10:21:00.500(2)? (STDERR) at Array.forEach (native)
W20140711-10:21:00.500(2)? (STDERR) at Function._.each._.forEach (/Users/mwho/.meteor/tools/858c88b520/lib/node_modules/underscore/underscore.js:79:11)
=> Exited with code: 8
Posts.js
Posts = new Meteor.Collection('posts');
Posts.allow({
update: ownsDocument,
remote: ownsDocument
});
Posts.deny({
update: function( userId, post, fieldNames ) {
// may only edit the following two fields:
return (_.without(fieldNames, 'url', 'title').length > 0);
}
});
Meteor.methods({
post: function(postAttributes) {
var user = Meteor.user(),
postWithSameLink = Posts.findOne({
url: postAttributes.url
});
// ensure the user is logged in
if (!user) throw new Meteor.Error(401, "You need to login to post new stories");
// ensure the post has a title
if (!postAttributes.title) throw new Meteor.Error(422, 'Please fill in a headline');
// check that there are no previous posts with the same link
if (postAttributes.url && postWithSameLink) {
throw new Meteor.Error(302,
'This link has already been posted', postWithSameLink._id);
}
// pick out the whitelisted keys
var post = _.extend(_.pick(postAttributes, 'url', 'title', 'message'), {
title: postAttributes.title + (this.isSimulation ? '(client)' : '(server)'),
userId: user._id,
author: user.username,
submitted: new Date().getTime()
});
//
// wait 5 seconds
if ( ! this.isSimulation ) {
var Future = Npm.require('fibers/future');
var future = new Future();
Meteor.setTimeout( function() {
future.return();
}, 5*1000);
future.wait();
}
var postId = Posts.insert(post);
return postId;
}
});
there is a typo in your code.
Posts.allow({
update: ownsDocument,
remote: ownsDocument
});
should be changed as
Posts.allow({
update: ownsDocument,
remove: ownsDocument
});

Resources