MCPcopy
hub / github.com/mongodb/node-mongodb-native / delete

Method delete

src/gridfs/index.ts:162–189  ·  view source on GitHub ↗

* Deletes a file with the given id * * @param id - The id of the file doc

(id: ObjectId, options?: { timeoutMS: number })

Source from the content-addressed store, hash-verified

160 * @param id - The id of the file doc
161 */
162 async delete(id: ObjectId, options?: { timeoutMS: number }): Promise<void> {
163 const { timeoutMS } = resolveOptions(this.s.db, options);
164 let timeoutContext: CSOTTimeoutContext | undefined = undefined;
165
166 if (timeoutMS) {
167 timeoutContext = new CSOTTimeoutContext({
168 timeoutMS,
169 serverSelectionTimeoutMS: this.s.db.client.s.options.serverSelectionTimeoutMS
170 });
171 }
172
173 const { deletedCount } = await this.s._filesCollection.deleteOne(
174 { _id: id },
175 { timeoutMS: timeoutContext?.remainingTimeMS }
176 );
177
178 const remainingTimeMS = timeoutContext?.remainingTimeMS;
179 if (remainingTimeMS != null && remainingTimeMS <= 0)
180 throw new MongoOperationTimeoutError(`Timed out after ${timeoutMS}ms`);
181 // Delete orphaned chunks before returning FileNotFound
182 await this.s._chunksCollection.deleteMany({ files_id: id }, { timeoutMS: remainingTimeMS });
183
184 if (deletedCount === 0) {
185 // TODO(NODE-3483): Replace with more appropriate error
186 // Consider creating new error MongoGridFSFileNotFoundError
187 throw new MongoRuntimeError(`File not found for id ${id}`);
188 }
189 }
190
191 /** Convenience wrapper around find on the files collection */
192 find(filter: Filter<GridFSFile> = {}, options: FindOptions = {}): FindCursor<GridFSFile> {

Callers 15

testFunction · 0.95
getTestOpDefinitionsFunction · 0.45
operations.tsFile · 0.45
bulk.test.tsFile · 0.45
testFunction · 0.45
setDifferenceFunction · 0.45
startSessionMethod · 0.45
checkInMethod · 0.45
makeClientMetadataFunction · 0.45
removeActiveCursorFunction · 0.45

Calls 3

resolveOptionsFunction · 0.90
deleteManyMethod · 0.80
deleteOneMethod · 0.45

Tested by 2

testFunction · 0.76
testFunction · 0.36