Meteor app crashes when trying to populate collections

rishat

This code works:

Schemas.City = new SimpleSchema({
    name: {
        type: String,
        label: 'City',
        unique: true
    }
});

Cities = new Mongo.Collection('cities');
Cities.attachSchema(Schemas.City);

This code works:

Meteor.startup(function() {
}

This code works:

Cities.insert([{
    name: 'Warszawa'
}, {
    name: 'Krakow'
}]);

But this code doesn't:

Meteor.startup(function() {
    if (Cities.find().count() == 0) {
        Cities.insert([{
            name: 'Warszawa'
        }, {
            name: 'Krakow'
        }]);
    }
}

I'm having the following error in console on server:

W20150911-13:34:52.281(4)? (STDERR) Error: 0 is not allowed by the schema
W20150911-13:34:52.281(4)? (STDERR)     at getErrorObject (packages/aldeed:collection2/collection2.js:417:1)

As you can see, I use aldeed:collection2 package to control data manipulations so that they stick to schema. The schema is simple and it only requires that there are no duplicates.

What's the right direction to move to discover the problem? Am I missing something?

Update: no arrays when inserting in Meteor

Okay, I got it. In Meteor, it's not possible to insert multiple entries into a collection using

Collection.insert([entry1, entry2, ...])

syntax. This, in turn, works:

Collection.insert(entry1);
Collection.insert(entry2);

So the problem is solved, mostly partially.

Alexander Kachkaev

batchInsert should be used in Meteor instead of insert in this case:

Collection.batchInsert([entry1, entry2, ...])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

App crashes when trying to implement multilingual support

From Dev

App crashes when trying to show AlertDialog in thread

From Dev

App crashes when trying to fullscreen activity

From Dev

App crashes when trying to record audio

From Dev

App crashes when trying to open a fragment with listview

From Dev

App crashes when trying to start a new activity

From Dev

App crashes when trying to connect to Neura service

From Dev

App crashes when trying to save to SQLite database

From Dev

App crashing when trying to populate a UITableView from NSMutableArray

From Dev

App crashing when trying to populate a UITableView from NSMutableArray

From Dev

App crashes when trying to add a row into table by pressing a button

From Dev

App crashes when trying to display three panoramic photos on one screen

From Dev

Visual Studio crashes when trying to associate Cordova app with store

From Dev

App crashes when nothing is entered in the TextBoxes I'm trying to parse

From Dev

App crashes when trying to access a viewcontroller from AppDelegate

From Dev

App crashes when trying to capture video using a camera intent

From Dev

My Android app crashes when trying to store SQLite data

From Dev

App crashes when trying to access array Android SDK

From Dev

Instagram crashes when my android app trying post on it using intent

From Dev

App crashes when nothing is entered in the TextBoxes I'm trying to parse

From Dev

App crashes when trying to connect to SignalR server after disconnecting it

From Dev

App Crashes When Trying to Set Wallpaper as Activity Background

From Dev

App crashes when trying to reuse toolbar by extending custom activity

From Dev

Android app crashes when trying to set a click listener on ImageButton in Fragment

From Dev

Meteor Collections and when to use a schema

From Dev

Trying to setText() crashes Android app

From Dev

Trying to parse a json crashes the app

From Dev

Trying to use sharedPreferences, but the app crashes

From Dev

Populate Expandable Listview from mysql crashes app

Related Related

  1. 1

    App crashes when trying to implement multilingual support

  2. 2

    App crashes when trying to show AlertDialog in thread

  3. 3

    App crashes when trying to fullscreen activity

  4. 4

    App crashes when trying to record audio

  5. 5

    App crashes when trying to open a fragment with listview

  6. 6

    App crashes when trying to start a new activity

  7. 7

    App crashes when trying to connect to Neura service

  8. 8

    App crashes when trying to save to SQLite database

  9. 9

    App crashing when trying to populate a UITableView from NSMutableArray

  10. 10

    App crashing when trying to populate a UITableView from NSMutableArray

  11. 11

    App crashes when trying to add a row into table by pressing a button

  12. 12

    App crashes when trying to display three panoramic photos on one screen

  13. 13

    Visual Studio crashes when trying to associate Cordova app with store

  14. 14

    App crashes when nothing is entered in the TextBoxes I'm trying to parse

  15. 15

    App crashes when trying to access a viewcontroller from AppDelegate

  16. 16

    App crashes when trying to capture video using a camera intent

  17. 17

    My Android app crashes when trying to store SQLite data

  18. 18

    App crashes when trying to access array Android SDK

  19. 19

    Instagram crashes when my android app trying post on it using intent

  20. 20

    App crashes when nothing is entered in the TextBoxes I'm trying to parse

  21. 21

    App crashes when trying to connect to SignalR server after disconnecting it

  22. 22

    App Crashes When Trying to Set Wallpaper as Activity Background

  23. 23

    App crashes when trying to reuse toolbar by extending custom activity

  24. 24

    Android app crashes when trying to set a click listener on ImageButton in Fragment

  25. 25

    Meteor Collections and when to use a schema

  26. 26

    Trying to setText() crashes Android app

  27. 27

    Trying to parse a json crashes the app

  28. 28

    Trying to use sharedPreferences, but the app crashes

  29. 29

    Populate Expandable Listview from mysql crashes app

HotTag

Archive