Update operation with aggregation pipelines
See original GitHub issueVersions
- NodeJS: 14.17.3
- mongodb-memory-server-*: 6.3.3
- mongodb: 4.4.10
- mongoose: 6.0.12
- system: Elementary OS 5.1.7 Hera Built on Ubuntu 18.04.6 LTS
package: Mongoose Testing (https://www.npmjs.com/package/@tsed/testing-mongoose)
What is your question?
I’m using TSED as a NodeJS framework (https://github.com/tsedio/tsed/issues/1604) and it uses a wrapper to the mongodb-memory-server in order to create automated tests.
The problem is that I’m not being able to use aggregation pipelines on updates. When running the application with MongoDB version 4.4.10 my code works, but in the test environment, it doesn’t.
Basically, I have a repository that executes a “find and replace” operation on a string property using the aggregate operator $replaceAll and then updates the current document.
async function findAndReplaceRecords(id: string, propName: string, payload: { find: string; replace: string }) {
const doc = await this.getDocumentById(id);
const { find, replace } = payload;
const pipeline = [
{
$set: {
records: {
$map: {
input: "$records",
as: "record",
in: {
$mergeObjects: [
"$$record",
{
[propName]: {
$replaceAll: {
input: `$$record.${propName}`,
find,
replacement: replace
}
}
}
]
}
}
}
}
}
];
return doc.updateOne(pipeline);
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top Results From Across the Web
Updates with Aggregation Pipeline — MongoDB Manual
The following db.collection.updateMany() operation uses an aggregation pipeline to update the documents with the calculated grade average and letter grade.
Read more >MongoDB: Modifying Documents Using Aggregation Pipelines ...
With MongoDB 4.4 and onwards, it is allowed to update a collection directly on the aggregate pipeline through the $merge stage. The magic ......
Read more >Aggregation with update in mongoDB - Stack Overflow
With Mongo 4.2 it is now possible to do this using update with aggregation pipeline. The example 2 has example how you do...
Read more >MongoDB: add/update fields referencing other existing ... - tsmx
Short explanation on how to add or update fields in documents referencing the values of ... Updating documents using aggregation pipelines.
Read more >MongoDB Update Pipeline Tricks - gists · GitHub
Starting with MongoDB 4.2, you can use aggregation pipelines to update documents. Which leads to some really cool stuff.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
distro
elementary
is not greatly supported before mongodb-memory-server version 7.0.0, please try to upgrade to 7.x or set the full download URL withDOWNLOAD_URL
(either via environment variables or package.json)Closing Issue because it is marked as stale