user3214030
user3214030

Reputation: 129

Anonymous `collection` error in `meteor Js`

I need a help for while creating the collection the below error is came in server console.How to solve the error ?

Error:

Warning: creating anonymous collection. It will not be saved or synchronized over the network. (Pass null for the collection name to turn off this warning.)

Upvotes: 2

Views: 435

Answers (1)

Hubert OG
Hubert OG

Reputation: 19544

TLDR: you need to provide a collection name as an argument when you create a shared collection.


In most cases, you want to provide a name as a parameter when you define a collection:

Docs = new Meteor.Collection('docs');

When you don't, you create anonymous collection:

Items = new Meteor.Collection();

In the first case, the collection is shared and synchronized between client and server, and the name you've provided is used as a table name in order to store the collection in Mongo.

Anonymous collections are local in the place they've been created. Their contents are never synchronized. Therefore, even if you create such collection in a piece of code that will be run on the server and on the client, those two collections will be separate things: data created on the server won't be visible on client, data created on the client won't be visible on server, and both won't be stored in the database.

There are legitimate use cases for anonymous collections, mostly on the client side when you need to create some temporary data, but want to retain all the benefits of Minimongo and reactivity. However, it's one of those things that are needed rarely and you really do know when you need to do it. It's more probable that a beginner made a mistake and forget to provide the collection name when he wanted to create a typical shared collection. Therefore, the system issues a warning to make sure that you really wanted to do what you just did.

Therefore:

If your goal was to create an anonymous collection, and you know what you're doing, don't worry about that message. It's just a warning, the code will be functional and do what it's told to.

If you wanted to create a normal collection, or are just starting out and don't know what's this all about, just add a parameter to your collection definition.

Upvotes: 3

Related Questions