Comments (8)
Thanks @valeeum, this would be a very nice improvement. Here is a suggested implementation: If $setOnInsert
is provided in the options
of etl.mongo.update
then:
- if its an Object, then the same Object will be included as
$setOnInsert
for every data packet in the bulk update - if its a function it will be called with the data for each packet and the results will be included in the corresponding
$setOnInsert
So if you wanted to set dateCreated
you could either do: etl.mongo.update(collection,keys,{upsert:true, $setOnInsert: new Date()})
(which will set all inserted records to the date when the bulk started) or etl.mongo.update(collection,keys,{upsert:true, $setOnInsert: function() { return new Date();}})
which would set it to the specific time each record was included in a bulk.
Let me know what you think or if you have other ideas?
from node-etl.
sorry about the delayed response...i was out of town.
i love the current minimalistic api but would like to have the additional flexibility to completely modify the argument passed in to the op.updateOne function.
op.updateOne({$set:d});
If the callback were supplied with the d variable as an argument, that would give the user the flexibility to craft whatever update operation they would like. $set is just one of many operators available to us. Comprehensive list of field update operators are provided here:
https://docs.mongodb.com/manual/reference/operator/update-field.
from node-etl.
Ah that makes sense - how about adding a new generic function etl.mongo.bulk
that simply passes on each incoming object directly to .updateOne
without wrapping it inside $set
. The keys of each objects would have to be any of the operators listed in the reference above? Let me know if you have better ideas?
from node-etl.
That sounds great! How would we differentiate a bulk insert vs bulk update (as well as the option to upsert)?
from node-etl.
Take a look at the changes I made here...
https://github.com/vcomedia/node-etl/blob/master/lib/mongo/update.js
I actually modified the existing etl.mongo.update function to allow flexibility to accommodate this use case as well as allow for backward compatibility (backward compatibility not yet tested but theoretically should work).
So we can now support feeding the following object to the function....
{
$setOnInsert: {
dateCreated: new Date(),
},
$set: {
dateModified: new Date()
},
$push: {
someArray: {
id: 'someID',
type: 'someType'
}
}
}
with the following keys...
['$push.someArray.id','$push.someArray.type']
The function will now walk the object using the dotted string notation and discard the first component starting with '$' character when creating the criteria since that signifies an update operation. So in this case, since the the keys start with an array operator ($push or $addToSet), the resulting query will be:
{
someArray : {
$elemMatch: {
id: 'someID',
type: 'someType'
}
}
}
$elemMatch is used instead of equality to prevent any issues with upsert operations. You can still use objects that represent property + values like the previous version using keys that don't include update operators. Only difference is that now there is support for dot notation for the keys.
Let me know what you think.
from node-etl.
Sorry for the delay - I'm back at my desk after the holidays and will take a better look in the next couple of days. Happy new year!
from node-etl.
I want to note I made one more update to address an error in mongo 3.4 caused by passing in the entire options variable into the bulk execute method. The new format I propose is to explicitly set the writeConcern object. This of course will break backward compatibility.
var writeConcern = self.options.writeConcern ? self.options.writeConcern : null;
bulk.execute(writeConcern,function(err,d) {
cb(err,self.options.pushResult && d);
});
Spec is available here:
https://docs.mongodb.com/manual/reference/method/Bulk.execute/
The entire update is available here:
https://github.com/vcomedia/node-etl/blob/master/lib/mongo/update.js
from node-etl.
Thanks again @valeeum - I folded your code into etl.mongo.bulk
to make it available for use.
I was a little hesitant to change the update
as this would break backwards compatibility.
We need to add tests and docs, and when we do a major release we could merge with update
published as + [email protected]
from node-etl.
Related Issues (20)
- Parallel processing HOT 1
- Postgres Upsert Requires All NOT NULL values to be included in the object.
- Typescript typings HOT 4
- Mongo insert is deprecated HOT 2
- Missing "pipeline" option in Elasticsearch
- fixed layout for binary source
- Postgres Upsert - Unique Field Support
- Old version of [email protected] has a dependency to "minimist": "^0.2.0" with a prototype pollution vulnerability HOT 1
- Can't change data type of field in Elasticsearch mapping
- SQL Server HOT 2
- __line HOT 1
- Mongo "pushResults" option
- Close mysql stream on error
- MSSQL Support HOT 1
- mongo ConnectAsync undefined
- ElasticSearch should retry with backoffs if transport error
- Elasticsearch concurrency option does nothing HOT 1
- Add AWS DynamoDB HOT 1
- etl.csv: strict: false - all headers lost after row with wrong number of columns for all following records
- Postgres upsert non-functional. HOT 1
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 node-etl.