meteor-mongo-minimongolisted
Install: claude install-skill meteor/agent-skills
# Mongo and Minimongo
Meteor ships two implementations of the Mongo API in one codebase. The server
talks to MongoDB through an async driver. The client runs Minimongo, an
in-memory synchronous Mongo emulator that holds the documents that
subscriptions have shipped.
## Decision flow
1. Where does this code run?
- Server-only: use `await Collection.*Async(...)`.
- Client-only: use `Collection.*(...)` synchronously.
- Isomorphic (`import` in shared code): use `await Collection.*Async(...)`.
On the client the work is local but still Promise-based; on the server it
talks to Mongo.
2. Does the query select more than a page of documents? Add `{ limit, skip }`
and an index that matches the selector.
3. Are you reading from a publication on the client? Use `find().fetch()`
(sync) without `await`. The data is already local.
## Server reads
```javascript
const doc = await Posts.findOneAsync(id);
const list = await Posts.find({ ownerId }, {
fields: { title: 1 }, sort: { createdAt: -1 }, limit: 50,
}).fetchAsync();
const count = await Posts.find({ ownerId }).countAsync();
```
## Server writes
```javascript
const _id = await Posts.insertAsync({ title, ownerId });
await Posts.updateAsync({ _id }, { $set: { title } });
await Posts.removeAsync({ _id });
```
## Client reads (Minimongo)
The async API is isomorphic. Prefer it in shared code so the same line works
on the server.
```javascript
const doc = await Posts.findOneAsync(id); // works