Meteor: Minimongo does not synchronize with MongoDB

时间秒杀一切 提交于 2019-12-25 08:58:43

问题


My Meteor application using Angular 2 and Typescript seems not to load the server data on the client side: I have followed this tutorial, both with autopublish turned on and of, but each time several tries to display data on client side with different collections failed.

Unlike in the tutorial (RC4), I am using Angular 2 RC5. My clients' main.ts looks as following:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule }              from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

Now I tried to copy the very simple sample from the tutorial using the collection "parties" (autopublish turned on).

I created the file both/collections/parties.collection.ts:

import {Mongo} from 'meteor/mongo';
import {Party} from '../interfaces/party.interface';
export const Parties = new Mongo.Collection<Party>('parties');

Instead of using the app.component.ts, I bind the collection in an another existing and functional component which looks like following:

import { Component } from '@angular/core';
import { Mongo } from 'meteor/mongo';
import template from './my-component.component.html';
import { Parties }   from '../../../both/collections/parties.collection';
import { Party } from '../../../both/interfaces/party.interface';

@Component({
selector: 'my-selector',
template
})

export class MyComponent
{
    parties: Mongo.Cursor<Party>;

    constructor() {
        this.parties = Parties.find();
        alert(this.parties.count());
    }
}

If I call db.parties.find({}); in the mongo console, it returns three rows, because I have set up the server side inserts from the sample.

My html template is the same as in the tutorial:

<ul>
<li *ngFor="let party of parties">
  <a [routerLink]="['/party', party._id]">{{party.name}}</a>
  <p>{{party.description}}</p>
  <p>{{party.location}}</p>
  <button (click)="removeParty(party)">X</button>
</li>

alert(this.parties.count()) returns "0" - both trying Mongo.Cursor and Mongo.Cursor. I have also tried to fetch the cursor and to alert the array. Each time I get "0" and the error message "NgFor only supports binding to Iterables such as Arrays.", but I think it fails because the client does not get the data the server has.


回答1:


This is no more an issue on recent versions of angular2.0-meteor.



来源:https://stackoverflow.com/questions/39452518/meteor-minimongo-does-not-synchronize-with-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!