swc/crates/swc_bundler/tests/.cache/deno/d706f02c673b871e257a62af5e9562e5c87ba103.ts
2021-11-09 20:42:49 +09:00

27 lines
784 B
TypeScript

// Loaded from https://deno.land/x/dndb@0.2.4/src/methods/update.js
import { mongobj, matches } from '../../deps.ts';
import { ReadFileStream, WriteFileStream } from '../storage.ts';
export default async (filename ,query, operators, projection) => {
const readStream = new ReadFileStream(filename);
const writeStream = new WriteFileStream(filename);
let updated = [];
query = query || {};
return new Promise((resolve, reject) => {
readStream.on('document', obj => {
if (matches(query, obj)) {
mongobj.update(obj, operators);
updated.push(obj)
}
writeStream.emit("write", obj)
})
readStream.on("end", () => {
writeStream.emit("end");
})
writeStream.on("close", () => {
return resolve(updated)
})
})
}