I'm just starting out with Meteor and working on a basic recipe list.
In my file (/imports/api/recipes.ts), I have defined my Recipe collection:
// imports/api/recipes.ts
export interface Recipe {
_id?: string;
title: string;
createdAt: Date;
}
export const RecipesCollection = new Mongo.Collection<typeof Recipe>("recipes");
It's easy to import and work with this collection on the client side (in a React component).
But here's the issue: Any changes I make don't seem to stick! Inserts briefly appear, but then revert in the browser when the "Optimistic UI" realizes the operation failed:
https://i.sstatic.net/qjuZb.png
The only way I've found to make it work is by interacting with the imported collection in server/main.ts. Simply including it via a named import doesn't do the trick.
Most resources suggest installing some "initial seed data" as a workaround, but I'm struggling to apply this concept in a more practical scenario.
If I import the collection in /server/main.ts without any action:
// server/main.ts
import { Meteor } from "meteor/meteor";
import { RecipesCollection } from "/imports/api/recipes";
Meteor.startup(async () => {});
The insert fails with the error shown in the screenshot above. However, if I perform a trivial action like this:
// server/main.ts
import { Meteor } from "meteor/meteor";
import { RecipesCollection } from "/imports/api/recipes";
Meteor.startup(async () => {
console.log(`On startup, saw ${RecipesCollection.find().count()} recipes`);
});
Then everything works as expected. Is there a simpler way to indicate to Meteor that I want this collection to be setup for server-side persistence and interaction with Mongo?