简体   繁体   中英

Cannot find a differ supporting object '[object Object]' of type 'object' , Error in meteor Collections

I am new to angular. I am following Course for angular2. I am trying to make a web application with angular and meteor js.

My browser reporting the error Cannot find a differ supporting object '[object Object]' of type 'object'

I have a mongo collection defined:

import {Mongo} from 'meteor/mongo';
export let Bookmarks = new Mongo.Collection('bookmarks');

And I am fetching records from the collection in my component.ts file

import { Component } from '@angular/core';
import template from './bookmarklist.html';
import {Bookmarks} from '../../../../collections/bookmarks';
import {Mongo} from 'meteor/mongo';


@Component({
  selector: 'bookmark-list',
  template: template
})
export class BookmarkList {
bookmarks : Mongo.Cursor<Object>;

constructor(){
    this.bookmarks = Bookmarks.find();
    console.log(this.bookmarks);
   }
}

Not sure where is the problem. I can retrieve record from the meteor mongo console...

Meteor Mongo Console

How about you first initiate the collection into a "const" and then export it as default:

const Bookmarks = new Mongo.Collections('bookmarks');
export default Bookmarks;

Exports can be "default" or if you export multiple constants you could export with brackets - add as {one, two, three}.

In your second snippet, I would first import meteor stuff, then everything else and the console log should be done on a find().fetch() cause find() returns a cursor not data.

console.log(Bookmarks.find().fetch());

Rgs, Paul

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM