New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types: typing error on bulkWrite
with AnyBulkWriteOperation<T>
#11985
Comments
Please include your imports on future issue submissions import * as mongoose from 'mongoose';
import * as mongodb from 'mongodb';
function modelBulkTest() {
interface ISchema {
_id: string;
num: number;
}
const schema = new mongoose.Schema({
_id: { type: String },
num: Number
});
const M = mongoose.model<ISchema>('Test', schema);
const ops: mongodb.AnyBulkWriteOperation<ISchema>[] = [
{
updateOne: {
filter: { _id: 'test' },
update: {
$inc: { num: 1 }
},
upsert: true
}
}
];
M.bulkWrite(ops);
}
modelBulkTest(); |
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days |
We have this problem as well. What can we provide to help you reproduce? And anything we can do to bandaid the problem? |
@RubenatorX a standalone a code sample that repros the issue you're seeing. Ideally please open a new issue and follow the issue template, but at least a code sample would be helpful. |
We have this issue, as well. I will attempt to describe the reason behind it, and I hope you find it useful: Type interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}, TSchema = any> extends
NodeJS.EventEmitter,
AcceptsDiscriminator,
IndexManager,
SessionStarter {
// ...
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation>, options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions, callback: Callback<mongodb.BulkWriteResult>): void;
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation>, callback: Callback<mongodb.BulkWriteResult>): void;
bulkWrite(writes: Array<mongodb.AnyBulkWriteOperation>, options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions): Promise<mongodb.BulkWriteResult>;
// ... As you can see, a type is not supplied (and cannot be supplied) to |
@keyCat so the issue you're seeing is that |
@vkarpov15 The issue is that |
Should be fixed by #12167 |
Hi, I just upgraded to 7.0.2 and suddenly I have this problem, code that was working just fine demands to be typed as this MongoDB type, but I've tried many configurations for getting it to realize that the data is already structured correctly and none of them work. Is there a way to bypass this? I've tried using "as AnyBulkWriteOperation" and "as AnyBulkWriteOperation" it never works |
@Kezzsim can you please open a new issue and follow the issue template? It is hard to figure out what's going on from an isolated screenshot. |
Prerequisites
Mongoose version
6.4.0
Node.js version
16
MongoDB server version
5
Description
bulkWrite
will show a typescript error if passed a variable of typeAnyBulkWriteOperation<ISchema>[]
Steps to Reproduce
Expected Behavior
The test should pass.
The text was updated successfully, but these errors were encountered: