Problems with $push
See original GitHub issueSo, I’m trying to push a mongo ObjectId into an array. The model is the following:
const videos = new Schema({
name: { type: String, required: true },
likes: [{ type: ObjectId, ref: 'users', default: [] }],
dislikes: [{ type: ObjectId, ref: 'users', default: [] }],
views: { type: Number, default: 0 },
}, {
timestamps: true
});
Then hooks are the following:
before: {
patch: [
authenticate('jwt'),
isValidAction(),
doLikeAction()
]
}
the doLikeAction
is the function not working
const doLikeAction = function(){
return function(hook) {
return new Promise((resolve, reject) => {
hook.app.service('users').find({ query: { _id: hook.params.user._id }})
.then(res => {
hook.app.service('videos').update(hook.id, { $push: { likes: res.data[0]._id } })
.then(res => {
console.log(res)
resolve(res)
})
.catch(err => {
console.log(err)
reject(new errors.BadRequest(constants.BAD_PARAMETERS));
})
})
})
}
}
It doesn’t say which error it is. The mongo ID are valid. The project is created using the yo generator. Hope you can help! Thank you 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
5 Common Pushup Mistakes and How to Avoid Them in Your ...
"The most common mistake people make with their pushups is flaring their elbows out as a result of using a hand position that's...
Read more >Your Push Up Problems Solved | Complete Beginner and Up
Discover how to perform the perfect push up for beginners and progress from not being able to perform the exercise to complete mastery...
Read more >3 Common Push Up Mistakes & How to Correct Them
Mistake #2 – Hips too low: It is vital to keep your hips level with your shoulders throughout the entire movement including the...
Read more >Here's the huge problem with push-button ignitions | Driving
Here's the huge problem with push-button ignitions ... per cent of 2014 model cars offering a push button ignition as standard or optional....
Read more >Why Isn't My Car's Push-Button Start Working?
Dead car battery. If your fob is working but your engine won't crank, your car may have a dead battery. To confirm that...
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 FreeTop 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
Top GitHub Comments
Everything works fine with update, but it’s not what I meant to use. My bad. If instead of
update
I usepatch
(which is what I want to use), then it always fail.The point is that I’m not understanding why it fails and the error is not helping 😦 Moreover, I also would like to populate the
likes
field of the model. By adding:and
it return a json with a
like
field in which there are the information relative to the current logged user (which_id
is not in thelikes
array).Thank for your reply hope you can help! 😃
@Fraccaman , Sorry my fault , the below code worked for patch