I just recently started to try learning Meteor.js. My intention is to build a newsfeed-feature where I can insert, edit and delete content. I’m stuck at the edit part.
imports/api/news/methods.js
Meteor.methods({
'news.insert'(content, title) {
check(content, String);
check(title, String);
// Make sure the user is logged in before insertig content
if (! Meteor.userId()) {throw new Meteor.Error('not-authorized');}
return News.insert({
content,
title,
createdAt: new Date(),
});
},
'news.remove'(newsId) {
check(newsId, String);
News.remove(newsId);
},
// Doesn't work?
'news.update'(content, title, newsId) {
check(content, String);
check(title, String);
check(newsId, String);
// user has to be logged in before updating content
if (! Meteor.userId()) {throw new Meteor.Error('not-authorized');}
News.update({_id: newsId}), {
$set: {
title:title,
content:content
}
}
}
});
I inserted a route that leads to the update-form for the content:
Edit
The update-form: imports/ui/components/news_edit/news_edit.html
<template name="NewsEdit">
<div class="col">
<small>Update: <b>{{news.content}}</b></small>
<form class='news-link-update'>
<input type="text" name="content" value="{{news.content}}" required> <small>ID: {{news._id}}</small> <br>
<br>
<textarea class="form-control" rows="5" id="comment" name="title" required>{{news.title}}</textarea>
<br>
<input type="submit" name="update" value="Update News" class="submit">
</form>
</div>
</template>
And the js-file which is calling the method: imports/ui/components/news_edit/news_edit.js
import { News } from '/imports/api/news/news.js';
import { Meteor } from 'meteor/meteor';
import './news_edit.html';
Template.NewsEdit.helpers({
news: ()=> {
var id = FlowRouter.getParam('id');
return News.findOne({_id: id});
}
});
Template.NewsEdit.events({
'submit .news-link-update'(event) {
event.preventDefault();
const target = event.target;
let newsId = target.dataset.newsId;
const title = target.elements.title;
const content = target.elements.content;
Meteor.call('news.update', title.value, content.value, newsId, (error, result) => {
if (error) {
console.log(newsId);
alert(error.reason);
}
});
},
});
I don't get a error 400 anymore but a 500-error. Internal server error.
The id is referenced now.
I20190222-04:22:58.230(1)? Exception while invoking method 'news.update' Error: Invalid modifier. Modifier must be an object.
I20190222-04:22:58.233(1)? at MongoConnection._update (packages/mongo/mongo_driver.js:495:11)
I20190222-04:22:58.233(1)? at MongoConnection.<anonymous> (packages\meteor.js:376:21)
I20190222-04:22:58.234(1)? at MongoConnection.(anonymous function) [as update] (packages/mongo/mongo_driver.js:754:49)
I20190222-04:22:58.234(1)? at _0xb3b0x8.(anonymous function).update (packages/mongo/collection.js:585:31)
I20190222-04:22:58.235(1)? at _0xb3b0x8.(anonymous function).Mongo.Collection.(anonymous function) [as update] (packages/aldeed:collection2/collection2.js:213:19)
I20190222-04:22:58.236(1)? at MethodInvocation.news.update (imports/api/news/methods.js:40:10)
I20190222-04:22:58.236(1)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1767:12)
I20190222-04:22:58.237(1)? at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20190222-04:22:58.237(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:22:58.238(1)? at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20190222-04:22:58.239(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:22:58.239(1)? at Promise (packages/ddp-server/livedata_server.js:715:46)
I20190222-04:22:58.242(1)? at new Promise (<anonymous>)
I20190222-04:22:58.242(1)? at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20190222-04:22:58.243(1)? at packages/ddp-server/livedata_server.js:559:43
I20190222-04:23:28.905(1)? Exception while invoking method 'news.update' Error: Invalid modifier. Modifier must be an object.
I20190222-04:23:28.906(1)? at MongoConnection._update (packages/mongo/mongo_driver.js:495:11)
I20190222-04:23:28.910(1)? at MongoConnection.<anonymous> (packages\meteor.js:376:21)
I20190222-04:23:28.911(1)? at MongoConnection.(anonymous function) [as update] (packages/mongo/mongo_driver.js:754:49)
I20190222-04:23:28.911(1)? at _0xb3b0x8.(anonymous function).update (packages/mongo/collection.js:585:31)
I20190222-04:23:28.912(1)? at _0xb3b0x8.(anonymous function).Mongo.Collection.(anonymous function) [as update] (packages/aldeed:collection2/collection2.js:213:19)
I20190222-04:23:28.912(1)? at MethodInvocation.news.update (imports/api/news/methods.js:40:10)
I20190222-04:23:28.913(1)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1767:12)
I20190222-04:23:28.914(1)? at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20190222-04:23:28.915(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:23:28.916(1)? at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20190222-04:23:28.918(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:23:28.918(1)? at Promise (packages/ddp-server/livedata_server.js:715:46)
I20190222-04:23:28.919(1)? at new Promise (<anonymous>)
I20190222-04:23:28.920(1)? at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20190222-04:23:28.920(1)? at packages/ddp-server/livedata_server.js:559:43
I20190222-04:25:34.580(1)? Exception while invoking method 'news.update' Error: Invalid modifier. Modifier must be an object.
I20190222-04:25:34.583(1)? at MongoConnection._update (packages/mongo/mongo_driver.js:495:11)
I20190222-04:25:34.584(1)? at MongoConnection.<anonymous> (packages\meteor.js:376:21)
I20190222-04:25:34.585(1)? at MongoConnection.(anonymous function) [as update] (packages/mongo/mongo_driver.js:754:49)
I20190222-04:25:34.585(1)? at _0xb3b0x8.(anonymous function).update (packages/mongo/collection.js:585:31)
I20190222-04:25:34.586(1)? at _0xb3b0x8.(anonymous function).Mongo.Collection.(anonymous function) [as update] (packages/aldeed:collection2/collection2.js:213:19)
I20190222-04:25:34.587(1)? at MethodInvocation.news.update (imports/api/news/methods.js:40:10)
I20190222-04:25:34.587(1)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1767:12)
I20190222-04:25:34.588(1)? at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20190222-04:25:34.593(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:25:34.594(1)? at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20190222-04:25:34.594(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:25:34.594(1)? at Promise (packages/ddp-server/livedata_server.js:715:46)
I20190222-04:25:34.595(1)? at new Promise (<anonymous>)
I20190222-04:25:34.596(1)? at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20190222-04:25:34.597(1)? at packages/ddp-server/livedata_server.js:559:43
I20190222-04:27:21.274(1)? Exception while invoking method 'news.update' Error: Invalid modifier. Modifier must be an object.
I20190222-04:27:21.277(1)? at MongoConnection._update (packages/mongo/mongo_driver.js:495:11)
I20190222-04:27:21.278(1)? at MongoConnection.<anonymous> (packages\meteor.js:376:21)
I20190222-04:27:21.279(1)? at MongoConnection.(anonymous function) [as update] (packages/mongo/mongo_driver.js:754:49)
I20190222-04:27:21.280(1)? at _0xb3b0x8.(anonymous function).update (packages/mongo/collection.js:585:31)
I20190222-04:27:21.280(1)? at _0xb3b0x8.(anonymous function).Mongo.Collection.(anonymous function) [as update] (packages/aldeed:collection2/collection2.js:213:19)
I20190222-04:27:21.281(1)? at MethodInvocation.news.update (imports/api/news/methods.js:40:10)
I20190222-04:27:21.282(1)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1767:12)
I20190222-04:27:21.283(1)? at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20190222-04:27:21.283(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:27:21.286(1)? at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20190222-04:27:21.286(1)? at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1304:12)
I20190222-04:27:21.287(1)? at Promise (packages/ddp-server/livedata_server.js:715:46)
I20190222-04:27:21.288(1)? at new Promise (<anonymous>)
I20190222-04:27:21.289(1)? at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20190222-04:27:21.289(1)? at packages/ddp-server/livedata_server.js:559:43
^ This is the new error log. What does the invalid modifier part mean?
You are getting Error: Invalid modifier. Modifier must be an object. error because of a syntax error in the update statement of the server method.
imports/api/news/methods.js
Meteor.methods({
...
news.update(content, title, newsId) {
check(content, String);
check(title, String);
check(newsId, String);
// user has to be logged in before updating content
if (! Meteor.userId()) {throw new Meteor.Error('not-authorized');}
// *** The parentheses was closed before '$set' was passed ***
News.update({_id: newsId}, {
$set: {
title:title,
content:content
},
{
multi:false // optional since by default it is false
}
});
}
});
Related
I'm trying to use wavesurfer.js in my vue front-end app. After I get the link to the audio file from the backend I get this error:
wavesurfer.js?8896:5179 Uncaught (in promise) TypeError: Cannot read property 'isPaused' of null
at WaveSurfer.empty (wavesurfer.js?8896:5179)
at WaveSurfer.load (wavesurfer.js?8896:4852)
at _callee$ (GameScreen.vue?dcce:42)
at tryCatch (runtime.js?96cf:63)
at Generator.invoke [as _invoke] (runtime.js?96cf:293)
at Generator.eval [as next] (runtime.js?96cf:118)
at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
at _next (asyncToGenerator.js?1da1:25)
at eval (asyncToGenerator.js?1da1:32)
at new Promise (<anonymous>)
This is the code I'm using in my vue component
<script>
import axios from 'axios';
import wavesurfer from 'wavesurfer.js';
export default {
name: 'GameScreen',
data(){
return {
isLoading: true,
}
},
mounted(){
this.initAudio();
},
methods: {
initAudio(){
axios.get('http://localhost:6060/track').then( async (response) => {
console.log(response.data);
const waveform = new wavesurfer({
container: this.$refs.wave,
color: 'violet',
backend: 'MediaElement'
});
await waveform.load(response.data);
await waveform.on('ready', () => {
this.isLoading = false;
//waveform.play();
});
console.log(waveform);
});
}
}
}
</script>
Is there any error in the code or something I can do to fix this?
UPDATE
The question is closed, I wanted to post the solution but not possible. Anyway the problem was with a typo I've made when the library is instantiated. I forget to call the create method. to instantiate correctly WaveSurfer the syntax is new WaveSurfer.create({...}) and not only new WaveSurfer({})
Thank you all for the help.
I am trying to take firebase backup through a cloud function. The function was running completely fine when I was using Runtime: Node.js 8. However, since it is going to be deprecated soon, I now have to use Node.js 10. My fcloud function now fails with the below error:
Error: function execution failed. Details:
Cannot read property 'charCodeAt' of undefined
Detailed error log:
2020-05-27 11:01:21.820 IST
firestore_export
8kxlp9s867dy
TypeError: Cannot read property 'charCodeAt' of undefined at peg$parsetemplate (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:304:17) at Object.peg$parse [as parse] (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:633:18) at new PathTemplate (/workspace/node_modules/google-gax/build/src/pathTemplate.js:55:54) at segments.forEach.segment (/workspace/node_modules/google-gax/build/src/pathTemplate.js:120:29) at Array.forEach (<anonymous>) at PathTemplate.render (/workspace/node_modules/google-gax/build/src/pathTemplate.js:114:23) at FirestoreAdminClient.databasePath (/workspace/node_modules/#google-cloud/firestore/build/src/v1/firestore_admin_client.js:904:57) at exports.scheduledFirestoreBackup (/workspace/index.js:6:31) at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/#google-cloud/functions-framework/build/src/invoker.js:330:28) at process._tickCallback (internal/process/next_tick.js:68:7)
Expand all | Collapse all
{
insertId: "000000-f688386c-8f2b-4146-aaf7-1fe67c656fa2"
labels: {…}
logName: "projects/firestore-249705/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2020-05-27T05:31:31.171084310Z"
resource: {…}
severity: "ERROR"
textPayload: "TypeError: Cannot read property 'charCodeAt' of undefined
at peg$parsetemplate (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:304:17)
at Object.peg$parse [as parse] (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:633:18)
at new PathTemplate (/workspace/node_modules/google-gax/build/src/pathTemplate.js:55:54)
at segments.forEach.segment (/workspace/node_modules/google-gax/build/src/pathTemplate.js:120:29)
at Array.forEach (<anonymous>)
at PathTemplate.render (/workspace/node_modules/google-gax/build/src/pathTemplate.js:114:23)
at FirestoreAdminClient.databasePath (/workspace/node_modules/#google-cloud/firestore/build/src/v1/firestore_admin_client.js:904:57)
at exports.scheduledFirestoreBackup (/workspace/index.js:6:31)
at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/#google-cloud/functions-framework/build/src/invoker.js:330:28)
at process._tickCallback (internal/process/next_tick.js:68:7)"
timestamp: "2020-05-27T05:31:21.820Z"
trace: "projects/firestore-249705/traces/74e27700d135763bc4e7892ebb1a2333"
}
My index.js is as below:
const firestore = require('#google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
// Replace BUCKET_NAME
const bucket = 'gs://gcp_firestore_ae2/firestore_export'
exports.scheduledFirestoreBackup = (event, context) => {
const databaseName = client.databasePath(
process.env.GCLOUD_PROJECT,
'(default)'
);
return client
.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
// Leave collectionIds empty to export all collections
// or define a list of collection IDs:
// collectionIds: ['users', 'posts']
collectionIds: ['most_valuable_items','nric_img','pay_slip','pic_of_ofc_entrance'],
})
.then(responses => {
const response = responses[0];
console.log(`Operation Name: ${response['name']}`);
return response;
})
.catch(err => {
console.error(err);
});
};
I had the same issue. I fixed it by changing:
process.env.GCLOUD_PROJECT
to my actual Project ID (e.g. "my_app_37274")
I had the same issue, It seems like in previous versions we don't need to GCLOUD_PROJECT in environment variable i.e it automatically detects it, but from node 10 onwards we need to pass this explicitly.
That's how I resolved it.
So instead of hardcoding it, try passing GCLOUD_PROJECT in cloud functions environment variables.
Note: GCLOUD_PROJECT is project id, not the project name.
I was performing development using ipfs - api, I encountered the following error, add of image file to ipfs node does not work well.
Looking at the details of the error, it seems that protocol is treated as undefined among if (protocol.indexOf ('https') === 0) { in request.js.
This is the error description
Uncaught (in promise) TypeError: Cannot read property 'indexOf' of undefined
at webpackJsonp../node_modules/ipfs-api/src/utils/request.js.module.exports (request.js:7)
at requestAPI (send-request.js:165)
at send (send-request.js:196)
at send-files-stream.js:99
at Function.promisify (add.js:41)
at index.js:32
at Object.add (add.js:60)
at VueComponent._callee$ (HaikuCompose.vue?0664:118)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:296)
This is the code I wrote
import IPFS from "ipfs-api"
const ipfsConf = { host: process.env.IPFSHOST, port: process.env.IPFSPORT, protocol: process.env.IPFSPROTCOL }
const ipfs = new IPFS(ipfsConf)
export default {
name: 'ipfstest',
data() {
return {
file:null,
buffer:null,
ipfsHash:null,
}
},
methods: {
async addipfs() {
await ipfs.add(this.buffer, (err, ipfsHash) => {
console.log(err,ipfsHash);
this.ipfsHash = ipfsHash[0].hash;
})
},
From the module sources, indexOf on line 7 of the request.js file is used on the variable storing the protocol, which is undefined in your case.
And from your code, I think I can safely assume that your environment variable process.env.IPFSPROTCOL is undefined.
TL:DR : I think you wanted to write IPFSPROTOCOL instead of IPFSPROTCOL
function facebookLogin() {
$cordovaOauth.facebook("948645908488914", ["email"]).then(function (result) {
displayData($http, result.access_token);
}, function (error) {
alert("Error: " + error);
});
}
I'm not certain what the email value should be. Should it be the user's email address from witch the token should be obtained from ?
I am receiving the following error:
TypeError: Cannot read property 'hasOwnProperty' of undefined
at Object.facebook (local://simulator/js/ng-cordova.min.js:24:6458)
at facebookLogin (local://simulator/js/app/controllers/ng-controllers-all.js:47:23)
at m.$scope.login (local://simulator/js/app/controllers/ng-controllers-all.js:43:9)
at fn (eval at <anonymous> (local://simulator/js/angular.min.js:210:400), <anonymous>:2:206)
at local://simulator/js/ionic-angular.min.js:20:5713
at m.$eval (local://simulator/js/angular.min.js:134:83)
at m.$apply (local://simulator/js/angular.min.js:134:309)
at HTMLButtonElement.<anonymous> (local://simulator/js/ionic-angular.min.js:20:5695)
at HTMLButtonElement.n.event.dispatch (local://simulator/js/jquery-2.1.4.min.js:3:6466)
at HTMLButtonElement.r.handle (local://simulator/js/jquery-2.1.4.min.js:3:3241)(anonymous function) # angular.min.js:107
email is the permission that you are asking for, You pass the permissions like:
$cordovaOauth.facebook("APP_ID", ['public_profile','user_friends','email','user_groups','user_likes']).then(function(result) {
// Code
the problem I guess is that you are not testing on a device.
Normally this type of error would not be a problem but i simply cannot understand where this is happening:
Here is my setup:
router.route('/api/academyModule')
.post(function (req, res) {
req.body.academyModule.module_id = req.body.academyModule.module.id;
req.body.academyModule.module_module_type_id = req.body.academyModule.module.module_type.id;
var am = AcademyModule.build(req.body.academyModule);
am.add(req.body.academyModule.requirements, req.body.academyModule, function (success) {
res.json({id: this[null]});
},
function (err) {
res.status(err).send(err);
});
if(req.body.teams != null)
{
req.body.teams.forEach(function(y)
{
var atm = academy_team_has_academy_module.build({academy_team_id: y.id, academy_id: y.academy_id, academy_module_module_id: req.body.academyModule.module_id })
atm.add(function(success)
{
}, function(err)
{
res.status(err).send(err);
});
});
}
})
For this i have the following model:
academy_team_has_academy_module = sequelize.define('academy_team_has_academy_module', {
academy_team_id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: false
},
academy_id: DataTypes.INTEGER,
academy_module_module_id: DataTypes.INTEGER
}, {
freezeTableName: true,
instanceMethods: {
add: function (onSuccess, onError) {
academy_team_has_academy_module.build(this.dataValues)
.save().ok(onSuccess).error(onError);
}
}
});
i know for sure this happens in this model and not AcademyModule because when i remove this code it runs without any issues. So in my console i get the following print out:
Executing (default): INSERT INTO `requirements` (`id`,`value`,`requirement_type_id`) VALUES (DEFAULT,5,'2');
Executing (default): INSERT INTO `academy_team_has_academy_module` (`academy_team_id`,`academy_id`,`academy_module_module_id`) VALUES (1,3,11);
Executing (default): INSERT INTO `academy_module` (`academy_id`,`module_id`,`module_module_type_id`,`sort_number`,`requirements_id`) VALUES ('3',11,4,4,40);
And just right after i get:
/var/www/learningbankapi/src/node_modules/mysql/lib/protocol/Parser.js:82
throw err;
^
TypeError: Cannot read property '1' of null
at module.exports.Query.formatError (/var/www/learningbankapi/src/node_modules/sequelize/lib/dialects/mysql/query.js:155:23)
at Query.module.exports.Query.run [as _callback] (/var/www/learningbankapi/src/node_modules/sequelize/lib/dialects/mysql/query.js:38:23)
at Query.Sequence.end (/var/www/learningbankapi/src/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Query.ErrorPacket (/var/www/learningbankapi/src/node_modules/mysql/lib/protocol/sequences/Query.js:93:8)
at Protocol._parsePacket (/var/www/learningbankapi/src/node_modules/mysql/lib/protocol/Protocol.js:271:23)
at Parser.write (/var/www/learningbankapi/src/node_modules/mysql/lib/protocol/Parser.js:77:12)
at Protocol.write (/var/www/learningbankapi/src/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.Connection.connect (/var/www/learningbankapi/src/node_modules/mysql/lib/Connection.js:82:28)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.stream.pause.paused (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:526:21)
Ive debugged the whole thing and i can't seem to find any undefined variables. What might have gone wrong here?
Your problem is a ForeignKeyContraintError. Sequelize is trying to throw a new error but get's an unexpected error.message. If your configuration is fine, this may be an bug of sequelize.
Maybe deactivating foreign contraint checks (if possible) will solve your problem.
See: https://github.com/sequelize/sequelize/blob/master/lib/dialects/mysql/query.js#L153