Comments (1)
const mongoose = require('mongoose');
const { Writable } = require('stream')
const testSchema = new mongoose.Schema({
name: String
});
const Test = mongoose.model('Test', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
for(let i = 0; i < 11; i++) {
await Test.create({ name: 'Apple' });
}
for(let i = 0; i < 11; i++) {
await Test.create({ name: 'Orange'})
}
const writableStream = new Writable({
write(chunk, encoding, callback) {
console.log(chunk.toString()); // Log the chunk to the console
callback(); // Call the callback to indicate that processing is complete
}
});
const otherStream = new Writable({
write(chunk, encoding, callback) {
console.log(chunk.toString()); // Log the chunk to the console
callback(); // Call the callback to indicate that processing is complete
}
});
console.log('find');
await Test.find({ name: 'Apple' }).cursor({ transform: JSON.stringify }).pipe(writableStream);
console.log('aggregate');
await Test.aggregate([{$match: { name: 'Orange' }}]).cursor({ transform: JSON.stringify }).pipe(otherStream);
console.log('done');
}
run();
from mongoose.
Related Issues (20)
- includeResultMetadata types not changing return type? HOT 5
- catching errors on streams HOT 4
- lack of documentation of middleware callback HOT 7
- MongoNetworkError: connect ETIMEDOUT ([Symbol(errorLabels)]: Set(1) { ‘ResetPool’ }) HOT 3
- Mongoose 8.x returns isValidObjectId false for twelve-character string that works in 7.x HOT 4
- When using replaceOne, the createdAt timestamp is being updated like the updatedAt HOT 2
- Find recursive records HOT 1
- How to properly handle watcher errors/disconnection HOT 3
- Flag to disallow passing undefined in queries globally HOT 3
- Populate Virtuals fails when localField is inside array (with reproduction code and data) HOT 3
- Why insertMany does not create ObjectIds in mongoose? HOT 1
- Unable to Subscribe to Certain MongoDB Client Events Before Connection HOT 3
- Add withSession() function HOT 1
- error : MongoNetworkError: connection 467 to *IP*:27017 closed
- Disable `select: false` fields to query from specific `find()` operations even try get explicitly. HOT 1
- Model.restore is broken when using use$neOperator = false HOT 2
- Transaction retries corrupt subdocument arrays HOT 4
- TypeScript Regression: deleteMany, deleteOne, replaceOne, updateMany, updateOne no longer support arbitrary options HOT 5
- Versioning does not work if the `versionKey` option for `toObject` is set to `false` when using `insertMany` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose.