I was creating a database storing user information. Previously, the system worked well, after I performed npm update of mongoose, the system failed and I dont know why. The following is the error message I encountered.
CastError: Cast to ObjectId failed for value "xxxxxxxxxxxxxxx" at path "_id" for model "User"
Then, I write some simple testing code to test if the database is connected successfully. For example:
User.findOne({firstName: "David"}, function(err, user){console.log(user.lastName)});
The above worked perfectly.
I then found the corresponding Id from the database directly and create variable like:
var testId = "abcde"
and tried the following code:
User.findById(testId, function(err, user){console.log(user.firstName)});
Then it just output the error messages.
I have tried mongoose.Types.ObjectId.isValid('abcde') (abcde is just example) and it returned true. Therefore, I really have no ideas why it did not work...is it a mongoose bug?
Please help if you know the answer, thank you very much!
I just solved the problem.
As I mentioned, the findById function did not work after I updated mongoose. I was struggling on the code for few days and when I woke up this morning, I suddenly thought of upgrading my node.js.
That worked.
After upgrading node.js from v4.x.x to latest version, everything worked fine : )
This taught me a lesson that I should not upgrade a single module alone and care of compatibility issue.
Related
pretty new to python, so i tried googling around for answers but i was probably googling the wrong terminology.
So here's my problem
i have this
objectName ="Account"
sf.bulk.objectName.upsert(dataToSalesforce,externalIdField, batch_size=10000)
The above command should send an upsert request for salesforce upserting on the account object, but it gives me the error {'exceptionCode': 'InvalidJob', 'exceptionMessage': 'Unable to find object: objectName'}
the problem is it tried to query the object objectName and not Account.
Everything works fine when i use: sf.bulk.Account.upsert(dataToSalesforce,externalIdField, batch_size=10000) but in the current use case the object being upserted to may change.
When looking at errors i noticed it used the term attribute, and googling using that term i found i could do this
getattr(sf.bulk, objectName).upsert(dataToSalesforce, externalIdField,batch_size=10000, use_serial=True)
which solves the issue
today when I try to run my Strapi with some exercises, there was an error showing that inversedBy attribute flight not found target api::airport.airport. However, the command shows Admin UI was built successfully. but I cannot access the Admin panel and do anything with it. It seems that the error is belonging to one of the content, but the entire API is not working. What should I do? Does anyone know how to fix this bug?
enter image description here
Thank you.
Firstly, I tried to run the start command(npm run develop) for several time, it keep reporting same error.
Secondly, I tried to access the administration panel directly, it is apparently that I failed.
Hopes someone can help me to figure out, how can I solve this bug/error.
I had a similar error.
The issue for me related to a problem where the 'key'(i.e. attribute key in JSON) didn't match that was referenced by the model in the mappedBy & inversedBy.
e.g. mappedBy:"f_light" should point to
"f_light":{type:"relation",...) --
At least that was the problem for me
Strapi Docs on how the schema is supposed to look
My issue: Error on attribute a_token in model a-request(api::a-request.a-request): inversedBy attribute a-requests not found target api::a-token.a-token
This occurred because I inversedBy:'a-token' when the attribute key was 'a_token'. Changing them so they matched solved my issue ('a-token' -> 'a_token').
The naming conventions of mappedBy, inversedBy, and the attribute keys MUST use '_' instead of '-' for spaces, otherwise it will fail the naming convention tests.
Ok so I just started looking into databases yesterday
index.js: https://hatebin.com/pvqnubsrrs
database.js: https://hatebin.com/csgvmvolfz
I just want it to insert into the DB,
how would I accomplish that?
Someone told me it's creating a new DB, but when I run the command it says the table doesn't exist
The error says:
Error: SequelizeDatabaseError: SQLITE_ERROR: no such table: PointsSystems
However, I cannot find a spot in the code where I use PointsSystems, I only use PointsSystem, without the s
Edit: Thank you SigFried for making this more readable.
The error says PointSystems because, by default, Sequelize will pluralize the name you gave to the table. Your code looks O.K, the only missing part and the solution to your problem is the await sequelize.sync({ force: true })}. I made a little example to show you how it's done in a very basic way.
You should be able to find out why the sequelize.sync() methods is needed if you read this.
Dear stackoverflow community,
I usually no make posts here, but in this time i ask myself why not?, after 2 hours without getting a solution.
This one is pretty basic but involves a specific json model, mongoose, mongodb and nodejs.
Now the problem, is that i´m trying to get the data for the user_ppal_id : 1 and the exam_design_id : 1 , the search of the user_ppal_id succeeded, but the exam_design_id that is into a nested array always returns to me the value 1 and 2 (and i´m passing by parameter the exam_design_id 1)...
This is my model, My nodejs rest method and how i´m using mongoose, nodejs and mongodb, My moongose model, A better view of the model from Umongo Ide:
SEE THE IMAGE HERE BECAUSE I AM NEW IN STACKOVERFLOW
All the structure is working, but the data from result is not the one i expected. You can check the response of this rest service by just clicking this url: http://207.244.75.230:8000/dyntestreports/getExamReport?idUserPpal=1&idExamDesign=1
In the response i´m getting the exam_design_id data for values 1 and 2 when i pass just the value 1.
Actually i tried with the following mongo queries and i not succeed:
1) ExamReportByUser.find({'user_ppal_id':userPpalId,'exams_created': {$elemMatch:{'exam_design_id': {$eq:examDesignId}}}}
2)ExamReportByUser.find({'user_ppal_id':userPpalId,'exams_created.0.exam_design_id':examDesignId}
At this moment i don´t know what i´m doing wrong even from a mongo console query i can´t get it works for just exam_design_id = 1 data.
I´m sure it could be a simple error but i´m not seeing it at this moment.
I really hope you can help me guys. Thanks in advance! Have a nice day.
My bad! I just have found the solution... And i post it here for anyone that had the same doubt... The code querying the data should be like this (it was just keys syntax, basic mongo):
ExamReportByUser.find({'user_ppal_id':userPpalId},{'exams_created': {$elemMatch:{'exam_design_id': examDesignId}}},'id user_ppal_id exams_created exam_design_id user_submitted_exam',function(err, result) { if (err) return console.log(err); return res.send(result); }); };
Now i´m getting the data of user 1 and exam_design 1.
I will not select this as an answer, waiting for the specialists ;)
I am facing a problem with mongoose Model.create method.
When i call
Model.create(arrayOfThousandDocs, function(err){});
After 15 min (sufficient for all the docs to get saved) when i switch to mongo shell and query upon total no of docs saved
then i find only something around 700-800 (no of docs saved varies every time Model.create is called).
And mongoose or mongo returns no any error.
Have anyone faced the same bug?
Please tell me how to resolve it.
it may be because, Model.create uses forEach method, and that is not suitable in nodejs asynchronous mode programming.. Please correct me if if i am wrong..
and suggest your views..
here is the source : http://mongoosejs.com/docs/api.html#model_Model.create