I want to perform a bulkUpdate, but came across an error that I don't understand.
The documentation for bulkUpdate in Loopback docs is very limited.
Can someone explain the proper usage of bulkUpdate, or what am I missing here?
ERROR Error while doing bulk inventory upload +0ms { [AssertionError: Cannot get a setup Change model for CategoryModel]
name: 'AssertionError',
actual: undefined,
expected: true,
operator: '==',
message: 'Cannot get a setup Change model for CategoryModel',
generatedMessage: false,
@kamal0808 bulk insert/create is a feature we are going to support, please check this issue for details(and feel free to Thumb up if you have same suggestion :-) ): https://github.com/strongloop/loopback/issues/1275#issuecomment-244983771
If you are still confused, please give me the link of the unclear doc, or provide me your sample code by fork https://github.com/strongloop/loopback-sandbox . Good luck!
Thanks @jannyHou , but #1275 focuses only on bulk insert/create. Now, I understand two of the ways/workarounds suggested in that thread: Model.create([array]) and Promise.all({createjob}).
However, they do not necessarily work for updates. As far as the loopback docs are concerned, I could only see this: https://docs.strongloop.com/display/APIC/Creating,+updating,+and+deleting+data#Creating,updating,anddeletingdata-Performingbulkupdates
It has no explanation whatsoever. I tried using the function mentioned in API docs (http://apidocs.strongloop.com/loopback/#persistedmodel-bulkupdate) but with no success.
Only if there was an explanation on how to use this function!
Are there any sample applications related to bulk update?
Also came accross this issue. The usage of bulkUpdates or createUpdates completely unclear. Would appreciate if anybody could describe if this is even implemented or going to work.
The current doc only has a link to bulkUpdate jsdoc: https://loopback.io/doc/en/lb3/Creating-updating-and-deleting-data.html#updating-data-model-instances
We need to figure out the correct way to use that api and add use case in a certain example repo.
Then update our doc as well.
BTW, @kamal0808 @benlime anyone runs into the error, could you elaborate more about the error message?
[AssertionError: Cannot get a setup Change model for CategoryModel]
Is Change a model you defined in loopback app or something from loopback itself? Thanks.
@jannyHou - No, only the term 'CategoryModel' comes from my project, rest everything is Loopback
Any news on this?
Only thing I can find on this is yet another issue https://github.com/strongloop/loopback/issues/2093 That basically says, nope it's mainly used for internal stuff. No real plans for doc'ing it.
@bajtos As per the discussion in #2093, if you guys don't intend to document this anytime soon, shouldn't it be removed from the API Docs sidebar menu as well? Right now, it just sits there with no documentation or use, that can easily misguide developers or waste their time trying to figure out its correct usage.
I lost 1 day trying to make this works :'v
Then i what can I do for bulk updates?
FYI
Sorry for the late reply, from my understanding bulkUpdate is used for replication, an example of how to use it is:
https://github.com/strongloop/loopback/blob/0448184a6cfcf239e5b9a7090e2b9b2852f9e99d/test/replication.test.js#L1616-L1626
From the test case, here is the usage of bulkUpdate: User have two models, e.g. TargetModel and SourceModel, after user do some CRUD changes to TargetModel, they call bulkUpdate to get SourceModel sync with TargetModel.
bulkUpdate takes in updates, options and a cb function,
updates:
@param {Array} updates An updates list, usually from createUpdates().
The code tells an update item includes
data: not sure what does this parameter meanchange: a change instance get by getChangeModel.find()type: the operation type: create, update, deleteoptions:
[options] An optional options object to pass to underlying data-access calls.
bulkUpdate eventually calls Model.updateAll(), Model.create(), Model.deleteAll(), and options should be passed into those functions.
@bajtos @raymondfeng can correct me or add more explanations, thanks :)
Let's remove the method from API docs then. I think we need to add @private annotation here: lib/persisted-model.js#L1396-L1404. The rendered API documentation can be verified by installing strong-docs via npm install -g strong-docs and then starting sdocs -p in loopback project.
It would be nice to hide other replication-related methods too: createUpdates, diff, changes, checkpoint, currentCheckpoint, findLastChange, and updateLastChange.
I think you don't need to remove data from the docs. Just clarify it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
@kamal0808 did you get any solution of your problem yet?
I started using mongo bulkupdate directly @eashkhatri-evon
Most helpful comment
Thanks @jannyHou , but #1275 focuses only on bulk insert/create. Now, I understand two of the ways/workarounds suggested in that thread:
Model.create([array])andPromise.all({createjob}).However, they do not necessarily work for
updates. As far as the loopback docs are concerned, I could only see this: https://docs.strongloop.com/display/APIC/Creating,+updating,+and+deleting+data#Creating,updating,anddeletingdata-PerformingbulkupdatesIt has no explanation whatsoever. I tried using the function mentioned in API docs (http://apidocs.strongloop.com/loopback/#persistedmodel-bulkupdate) but with no success.
Only if there was an explanation on how to use this function!