New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on MongoDB insertion #6787
Comments
@RomainJamet Thanks for posting! We'll take a look as soon as possible. In the mean time, there are a few ways you can help speed things along:
Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly. For help with questions about Sails, click here. |
Oh, in case you're wondering, in my attempt example code, the function to() is a Promise wrapper, that looks like:
To avoid having to put a try-catch block at each await I'm using. |
Alright, I've found a workaround derived from the previously attempted solution. Instead of directly trying to successively call
Then I call this method from the controller in a loop:
Basically, I'm awaiting for a promise that's awaiting for create's promise. Since the volume of data is not too big, this will do for now, but I'd like to know if the previously observed behaviors (reusing the same ids despide the |
@RomainJamet Thanks for the great detail on this one and providing a workaround. I'll bring this up with the team to determine the best reason why it's reusing the same ids despite the await create() calls being successive (await createEach() not automatically generating ids.) If you have a repo, that will also help. Appreciate the efforts 👍 |
I'm experiencing this issue now as well, has this been resolved? |
Hi @laurenamy, can you provide us with more information about your version info? Are you using multiple adapters or just sails-mongo? |
Node version: 10.15.1
Sails version (sails): 1.2.2
ORM hook version (sails-hook-orm): 2.1.1
Sockets hook version (sails-hook-sockets): 1.5.5
Organics hook version (sails-hook-organics): N/A
Grunt hook version (sails-hook-grunt): 3.1.0
Uploads hook version (sails-hook-uploads): N/A
DB adapter & version (e.g. sails-mysql@5.55.5): sails-mongo@1.0.1
Skipper adapter & version (e.g. skipper-s3@5.55.5): N/A
Hello,
I currently have a problem with the sails-mongo adapter.
We have a SailsJS that has been using Postgresql for a while, it was created in 0.10 and updated recently to 1.2.2. We halso have a MongoDB database that is primarily used by another application, but we need to periodically collect data from this MongoDB base.
Previously, we used the mongoose module to do any operation on this base, but we wish to use the built-in solution with Waterline, and add our MongoDB base as a datastore.
I added it to the list of datastores, declared my models, and I did override the default id with MongoDB's _id, as described in SailsJS's documentation.
When I try to find data: everything seems fine, all my data are correctly retrieved. But when I tried to create objects in the MongoDB datastore, it failed.
First I tried to insert an array of objects, which prompted the following error:
Apparently, it expected that I put something in the id field, which is impossible, as I wish to use MongoDB's default id system (since all existing data uses it).
So I tried to insert elements once at a time, and I got an even weirder error:
I tried to insert 5 elements from an array, once at a time (with await create(element).toPromise()), the first element was inserted properly:
But then for the following one:
Apparently it tried to use the same id. And the third item was inserted properly with another id, but not the fourth which used the third's id and so on....
So createEach does not generates ids, and successive create calls fail once of two times.
Here's my model file:
My successive create attempts looks like:
With fakethreads being an array of objects containing all of my model's attributes except ids.
The text was updated successfully, but these errors were encountered: