Search code examples
mongodbmeteorcodemirror

CodeMirror error with MeteorJs


I'm using meteorJs 1.4 and trying to use the mizzao:sharejs-codemirror package but I keep getting this error when I try to use it

failed to get ops for tNvo2iHyPAamPeHAd: MongoError: Failed to parse: sort: "_id.v". 'sort' field must be of BSON type Object.

here is some code: server side

this.Documents = new Mongo.Collection("documents");

Meteor.startup(() => {
  if(!Documents.findOne()){
    Documents.insert({title:"new Document"});
  }
});

client side:

this.Documents = new Mongo.Collection("documents");

Template.editor.helpers({
  docid:function(){
    myDocument = Documents.findOne();
    if(myDocument){
      return myDocument._id;
    }
    else{
      return undefined;
    }
  }
});

markup:

<head>
  <title>textcircle</title>
</head>

<body>
  <h1>welcome to textcircle</h1>

  {{> editor}}
</body>

<template name="editor">
  {{> sharejsCM docid=docid id="editor"}}
</template>

Can someone please explain to me what this means. Thanks.


Solution

  • I'm not sure if this will completely help in your case but apparently there are some issues with Meteor 1.4 and shareJS / CodeMirror (check the repo for more info), so this is a workaround. I was running Meteor 1.4 and also building an app using shareJS / CodeMirror but mine would get stuck on "loading..." in the code mirror pane / div and not get any further (using Firefox on Ubuntu). First, I tried "meteor reset" but that didn't fix it. I tried just running Meteor as a previous version with a command switch but the MongoDB would fail to start. I tried creating a project instead with 1.3.x and was still having the same issue, but when I created a new Meteor app with version 1.2.1 it worked and the CodeMirror pane was functional.

    To create a new Meteor 1.2.1 app, run:

    meteor create [appName] --release 1.2.1

    To get it up and going, I copied my client and server files over from my 1.4 app, and deleted the auto-generated files. I commented out the import statements, but other than that it was pretty smooth. Just add the packages you're using and you'll have to add session too most likely, but that should get you up and running.