Automattic / Automattic/mongoose
Add option to queue operations until `autoCreate` and `autoIndex` finish
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 35
Description
I have a problem when I switch database before creating timeseries.
it will creates a collection instead o f timeseries.
Here's the code
```typescript
// db.ts
export const useDB = (guidId: string) =>
mongoose.connection.useDb(guidId, {
// ensures connections to the same databases are cached
useCache: true,
// remove event listeners from the main connection
noListener: true,
});
// =====================================
// schema file
import { useDB } from 'db';
import mongoose, { Schema } from 'mongoose';
export interface ActiveUserDoc {
timestamp: Date;
messages: Number;
metadata: { discordId: string };
}
const ActiveUserSchema = new Schema(
{
timestamp: Date,
messages: Number,
metadata: {
discordId: String,
},
},
{
timeseries: {
timeField: 'timestamp',
metaField: 'metadata',
granularity: 'hours',
},
expireAfterSeconds: 60 * 24 * 7, // 7 days
},
);
export const getModel = (guildId: string) =>
useDB(guildId).model>(
'ActiveUser',
ActiveUserSchema,
'active_user',
);
```

_Originally posted by @satasuk03 in https://github.com/Automattic/mongoose/issues/10611#issuecomment-1150794186_
Note:
Mongoose Version: 6.3.6
Node Version: 16.13.1
MongoDB Version: 5.0.9
Contributor guide
Assessment
This issue has not been assessed yet.