Why does Meteor complain that an insert method for a collection is already defined? - collections

Can anyone tell me why the code below throws the following error? :
Error: A method named '/players/insert' is already defined
I'm new to Meteor and coffeescript so I may be overlooking something simple.
Here's my port of the leaderboard example to coffeescript:
###
Set up a collection to contain player information. On the server,
it is backed by a MongoDB collection named "players."
###
Players = new Meteor.Collection("players")
if Meteor.is_client
Template.leaderboard.players = ->
Players.find({}, {sort: {score: -1, name: 1}})
Template.leaderboard.selected_name = ->
player = Players.findOne(Session.get "selected_player")
player and player.name
Template.player.selected = -> if Session.equals("selected_player", this._id) then "selected" else ''
Template.leaderboard.events = {
'click input.inc': ->
Players.update(Session.get("selected_player"), {$inc: {score: 5}})
}
Template.player.events = {
'click': ->
Session.set("selected_player", this._id)
}
# On server startup, create some players if the database is empty.
if Meteor.is_server
Meteor.startup ->
if Players.find().count() is 0
names = [
"Ada Lovelace"
"Grace Hopper"
"Marie Curie"
"Carl Friedrich Gauss"
"Nikola Tesla"
"Claude Shannon"
]
Players.insert({name: name, score: Math.floor(Math.random()*10)*5}) for name in names
The full stack trace is as follows:
[[[[[ ~/dev/meteor/leaderboard ]]]]]
Running on: http://localhost:3000/
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: A method named '/players/insert' is already defined
at app/packages/livedata/livedata_server.js:744:15
at Function.<anonymous> (app/packages/underscore/underscore.js:84:24)
at [object Object].methods (app/packages/livedata/livedata_server.js:742:7)
at new <anonymous> (app/packages/mongo-livedata/collection.js:111:13)
at app/leaderboard.js:4:11
at /Users/alex/dev/meteor/leaderboard/.meteor/local/build/server/server.js:109:21
at Array.forEach (native)
at Function.<anonymous> (/Users/alex/dev/meteor/leaderboard/.meteor/local/build/server/underscore.js:76:11)
at /Users/alex/dev/meteor/leaderboard/.meteor/local/build/server/server.js:95:7
Exited with code: 1
I'm running Meteor version 0.4.0 (8f4045c1b9)
Thanks in advance for assistance!

You would also get this error, regardless of using coffeescript or plain javascript, if you duplicated your files. For example, copying your sources files to a subdirectory named Backup would produce this error, because Meteor merges files from subdirectories.

This appears to be a configuration issue with coffeelint (installed globally with npm).
I originally installed coffeelint to check that my coffeescript code was correct and had no errors.
I installed coffeelint as per the instructions with:
sudo npm install -g coffeelint
coffeelint worked fine when run stand-alone against .coffee files.
However, when running any Meteor project with coffeescript package added I got the above error.
On a whim, I thought the error might be due to conflict with my exisiting node install.
I decided to uninstall coffeelint first with:
sudo npm uninstall -g coffeelint
and then deleted the previously meteor-generated leaderboard.js file.
After re-starting meteor the coffeescript example above worked as expected without errors.

try moving (ie copying and deleting the original )
Players = new Meteor.Collection("players")
one time below if Meteor.is_client
and another time below if Meteor.is_server
I don't know exactly why, as I'm new to Meteor too, but that worked for me, I assume that the server side needs it's own reference,as well as the client,
although declaring outside the scope should do the same (maybe a bug, remember they're still at 0.5.0 preview , which makes me think you might wanna upgrade and try some new smart packages that are with the new version, it looks like you're using 0.4), but when the files in my server wouldn't recognize anything I defined the root directory of meteor (which pushes these files to both client and server), I defined the server's own reference, and I got the same error, and until I moved the 'public' declaration of the reference to give the server and the client each their own copy, nothing worked.
Hopefully that helps...

Related

Grunt error with fs.unlinkSync on Sails

I'm using skipper to receive the files, sharp to resize (and save) and fs unlink to remove the old image. But I got a very weird error this time that concerns me a lot:
error: ** Grunt :: An error occurred. **
error:
Aborted due to warnings.
Running "copy:dev" (copy) task
Warning: Unable to read "assets/images/users/c8e303ca-1036-4f52-88c7-fda7e01b6bba.jpg" file (Error code: ENOENT).
error: Looks like a Grunt error occurred--
error: Please fix it, then restart Sails to continue running tasks (e.g. watching for changes in assets)
error: Or if you're stuck, check out the troubleshooting tips below.
error: Troubleshooting tips:
error:
error: *-> Are "grunt" and related grunt task modules installed locally? Run npm install if you're not sure.
error:
error: *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
error:
error: *-> Or maybe you don't have permissions to access the .tmp directory?
error: e.g., (edited for privacy)/sails/.tmp ?
error:
error: If you think this might be the case, try running:
error: sudo chown -R 1000 (edited for privacy)/sails/.tmp
Grunt stopped running and to have that in production is a big NoNo... I believe that this is caused because of concurrency with fs.unlinkSync(fname). The error is also intermittent and very hard to reproduce in some machines (IO ops/sec maybe?).
I have the following controller action:
var id = 1; // for example
req.file('avatar').upload({
dirname: require('path').resolve(sails.config.appPath, 'assets/images')
}, function(err, files){
var avatar = files.pop();
//file name operations here. output is defined as the path + id + filetype
//...
sharp(avatar.fd)
.resize(800, 800)
.toFile(output, (err, info)=>{
if(err){
res.badRequest();
} else {
fs.unlinkSync(avatar.fd);
res.ok();
}
});
});
Now I've been thinking about a few solutions:
Output the new image directly to .temp
Unlink when files exists on .tmp. Explanation: Grunt already copied the old file so removing it would be safe!
But I don't know if this is some spaghetti code or even if a better solution exists.
EDIT: My solution was, as proposed by arbuthnott, wrap a controller like this:
get : function(req, res){
var filepath = req.path.slice(1,req.path.length);
//remove '/' root identifier. path.resolve() could be used
if(fs.existsSync(path.resolve(filepath))){
return res.sendfile(filepath);
} else {
return res.notFound();
}
}
I think you are on the right track about the error. You are making some rapid changes to in the assets folder. If I read your code right:
Add an image with user-generated filename to assets/images (ex cat.jpg)
Copy/resize the file to an id filename in assets/images (ex abc123.jpg)
Delete the original upload (cat.jpg)
(I don't know the details of sharp, there may be more under the hood there)
If sails is running in dev mode, then Grunt will be trying to watch the whole assets/ folder, and copy all the changes to .tmp/public/. It's easy to imagine Grunt may register a change, but when it gets around to copying the added file (assets/images/cat.jpg) it is already gone.
I have two suggestions for the solution:
One:
Like you suggested, upload your original to the .tmp folder (maybe even a custom subfolder of .tmp). Still place your sized copy into /assets/images/, and it will be copied to /.tmp/public/ where it can be accessed as an asset by the running app. But Grunt will ignore the quick add-then-delete in the .tmp folder.
Two:
Do a bit of general thinking about both what you want to include in version control, and what Grunt tasks you want to be running in production. Note that if you use sails lift --prod then Grunt watch is turned off by default, and this error would not even occur. Generally, I don't feel like we want Grunt to do too much in production, it is more of a development shortcut. Specifically, Grunt watch can use a lot of resources on a production server.
The note about version control is just that you probably want some of the contents of assets/images/ to be in version control (images used by the site, etc), but maybe not in the case of user-uploaded avatars. Make sure you have a way to differentiate these contents (subdirectories or whatever). Then they can be easily .git-ignore'd or whatever is appropriate.
Hope this helps, good luck!

basic React Native SQLite script returning undefined which causes error

I'm trying to learn to use react-native-sqlite-storage as described on this page here:
https://github.com/andpor/react-native-sqlite-storage
I am working on a windows machine trying to build an android app. I have the following code:
import SQLite from 'react-native-sqlite-storage';
function errorCB(err) {
console.log("SQL Error: " + err);
}
function successCB() {
console.log("SQL executed fine");
}
function openCB() {
console.log("Database OPENED");
}
var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
db.transaction((tx) => {
tx.executeSql('SELECT * FROM Employees a, Departments b WHERE a.department = b.department_id', [], (tx, results) => {
console.log("Query completed");
});
});
export default 1;
When I run this, I get the error
undefined is not an object (evaluating
'NativeModules["SQLite"][method]')
The error is happening on the line var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
I suspect the reason the error is happening is because SQLite expects the existence of a database before you can actually open it. However, I do not see any instructions in the link above on how to create a database with react-native-sqlite-storage, so I'm not sure if my assumption is correct. Additionally, I assume I'd need to have a table for Employees, but again, the link above didn't explicitly state examples on how to create one. SO I don't know if my assumption is correct.
So how do I get SQLite.openDatabase() command to work?
More information
I deleted my project. Then I tried to re-install everything again, this time closely following the installation instructions for sqlite storage for android as mentioned on the andpor's github instructions (ie, modifying gradle files, updating MainApplication class etc...). Once I did that, running the command react-native run-android from the CLI causes this build error:
ERROR EPERM: operation not permitted, lstat 'C:\Users\John
Lai\Projects\ReactNative\myapp\android\app\build\intermediates\exploded-aar\myapp\realm\unspecified\jars\classes.jar'
{"errno":-4048,"code":"EPERM","syscall":"lstat","path":"C:\Users\John
Lai\Projects\ReactNative\myapp\android\app\build\intermediates\exploded-aar\myapp\realm\unspecified\jars\classes.jar"}
Error: EPERM: operation not permitted, lstat 'C:\Users\John
Lai\Projects\ReactNative\myapp\android\app\build\intermediates\exploded-aar\myapp\realm\unspecified\jars\classes.jar'
at Error (native)
I tried running this command as a regular user and as an administrator, and still the same issue.
More Information 2
I deleted my project. Then I did npm install for all my projects. Then I tried the commands rnpm link and react-native link react-native-sqlite-storage, both of which gave this error:
ERR! It seems something went wrong while linking. Error: spawn UNKNOWN
Please file an issue here: https://github.com/rnpm/rnpm/issues
So now the project won't even build. Any ideas?
the problem is the library is not linked
to link they suggest two ways
with pod (advanced)
with rnpm link (easy) but this command is deprecated
so to link the library you should use the
react-native link react-native-sqlite-storage
this command is equal to rnpm link but not deprecated
if automatic build failing try with manual linking for iOS manually linking ios and android manually linking android
lstat command error is generating on windows due to permission issues or npm version issues.
You can do 2 things to pass this.
1.Open terminal in admin mode .
2.upgrade/degrade npm version
For plugin installation, configure manually
You need change MainApplication.java with:
import org.pgsqlite.SQLitePluginPackage;
and
in getPackages:
new SQLitePluginPackage()

Sudden syntax error after deployment

I have a working symfony project. I have it on a private bitbucked repository and locally the website works without an issue.
Today I tried to deploy the project onto an external server linuxpl.com.
Steps taken include:
Istalling composer
Adding the mysql database
Running git clone to get the data into a proper location
Running composer install on the folder to install everything and connect to the db
Cleared the cache
Set the project root as ....domain/project_name/web
However after completing all these steps, when running the website with regular server:run I'm getting this odd error:
Parse error: syntax error, unexpected '.' in /home/spirifer/domains/surowcewobiektywie.pl/konkurs/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1571
Not sure if this is of any importance but the mentioned code partion looks like this in my local files:
// Some objects throw exceptions when they have __call, and the method we try
// to call is not supported. If ignoreStrictCheck is true, we should return null.
try {
$ret = $object->$method(...$arguments);
} catch (BadMethodCallException $e) {
if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) {
return;
}
throw $e;
}
The local version does not differ from the one on the server.
My local machine has PHP 7.0.9 and the remove server has PHP 7.0.14
How could I fix this issue?
PHP 5.6 adds Variadic functions, with "...". However, Twig v1.x only required the use of PHP 5.2.7 or above.
If you didn't explicitly update to Twig 2.0, it's very possible you have used the 'death star' version constraint in the composer file - '*'. which allows uncontrolled version updates to the latest version. If this is the case, you will need to either update your version of PHP, or at least require just a previous version of Twig/twig, "^1.32" would be the latest in the version 1 series of Twig.

Meteor: Could not resolve the specified constraints for this project: Unknown package

What are the constraints that Meteor is trying to resolve when it loads the packages at startup? Is it all related to versioning or is it actually looking at the code that you load with ap.use() in packages.js?
I am getting this error when I try to start up my project. I have a super-simple package file that I created with the meter create --package command. I put all of my files that make up the package into the directory that it created and moved that directory to .meteor/packages. I'm just trying to create a local package for now. Here's the contents of package.js in that directory:
Package.describe({
name: 'ammap-meteor',
summary: 'mapping library packaged for meteor ',
version: '1.0.0',
});
Package.onUse(function(api) {
api.versionsFrom('METEOR#0.9.0');
api.addFiles('ammap.js');
api.addFiles('ammap_amcharts_extension.js');
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('ammap-meteor');
api.addFiles('ammap-meteor-tests.js');
});
My ammap-meteor-tests.js file is blank for the moment but it exists. Would that make a difference? And I assume you just omit the git: property from Package.onUse() for a local package, is that right?
OK, I was able to get past that error with the publish command:
meteor publish --create
So I did not succeed in making a local package (still not clear on that) but at least I can get the package to load now.

meteor Uncaught ReferenceError: Tracker is not defined

I'm getting the following error - Uncaught ReferenceError: Tracker is not defined
I am running meteor under windows(meteor version 0.8.3).
The code is in my templates js file.
Tracker.autorun(function (c) {
if (MovieTrailers.find().fetch().length == 0)
return;
c.stop();
PlayCurrentTrailer();
});
So far I have tried :
meteor add deps
But that didn't work.
Is tracker available under 0.8.3? or am I missing a package?
tracker is the new name of deps, so replace the occurrence of tracker in your code with deps and you're good to go.
Try to avoid running older versions of Meteor to develop new code, can't you run a VM or use an online service like Nitrous.io for development purpose, as deploying a Meteor app to production in a Windows environment for the moment is not going to happen anytime soon ?

Resources