Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to insert documents in a loop?
    text
    copied!<p>I am iterating over a moment-range daterange and trying to insert documents. I am getting the following error:</p> <pre><code>Exception while simulating the effect of invoking '/carpool_events/insert' Error Error: Sorting not supported on Javascript code at Error (&lt;anonymous&gt;) at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo/selector.js? 5b3e1c2b868ef8b73a51dbbe7d08529ed9fb9951:251:13) at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo/selector.js? 5b3e1c2b868ef8b73a51dbbe7d08529ed9fb9951:226:36) at LocalCollection._f._cmp (http://localhost:3000/packages/minimongo/selector.js?5b3e1c2b868ef8b73a51dbbe7d08529ed9fb9951:218:33) at _func (eval at &lt;anonymous&gt; (http://localhost:3000/packages/minimongo/sort.js?08a501a50f0b2ebf1d24e2b7a7f8232b48af9057:63:8), &lt;anonymous&gt;:1:51) at Function.LocalCollection._insertInSortedList (http://localhost:3000/packages/minimongo/minimongo.js?7f5131f0f3d86c8269a6e6db0e2467e28eff6422:616:9) at Function.LocalCollection._insertInResults (http://localhost:3000/packages/minimongo/minimongo.js?7f5131f0f3d86c8269a6e6db0e2467e28eff6422:534:31) at LocalCollection.insert (http://localhost:3000/packages/minimongo/minimongo.js?7f5131f0f3d86c8269a6e6db0e2467e28eff6422:362:25) at m.(anonymous function) (http://localhost:3000/packages/mongo-livedata/collection.js?3ef9efcb8726ddf54f58384b2d8f226aaec8fd53:415:36) at http://localhost:3000/packages/livedata/livedata_connection.js?77dd74d90c37b6e24c9c66fe688e9ca2c2bce679:569:25 </code></pre> <p>This is my loop with the insert. I have tested the loop by just writing to console.log instead of inserting and the loop works fine</p> <pre><code> 'click button.save-addEventDialogue': function(e, tmpl) { var start = Session.get("showAddEventDialogue_dateRangeStart"); var end = Session.get("showAddEventDialogue_dateRangeEnd"); var dateRange = moment().range(moment(start),moment(end)); var dateLoopIncrement = moment().range(moment(start),moment(start).add('days',1)); console.log(dateRange); console.log(dateLoopIncrement); // Loop through the date range dateRange.by(dateLoopIncrement, function(moment) { // Do something with `moment` var dateToSave = dateRange.start; // Insert the record Carpool_Events.insert({ owner: Meteor.user().profile.name, owner_id: Meteor.userId(), original_owner: Meteor.user().profile.name, original_owner_id: Meteor.userId(), declined: 0, date: dateToSave.toDate() }); dateToSave.add('days',1); }); // Clear the Session Session.set("showAddEventDialogue_dateRangeStart",""); Session.set("showAddEventDialogue_dateRangeEnd",""); // Close the dialogue Session.set("showAddEventDialogue", false); } </code></pre> <p>What is the right way to do this? Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload