Remove from array[ObjectId]
See original GitHub issueHello,
How can I remove a ObjectId from a array of ObjectId ?
My model :
var User = new Schema({
title : { type : String, index: true },
name : String,
friends : [ObjectId],
join_at : {type:Date, default:Date.now },
save_at : {type:Date, default:Date.now }
});
The function for deleting the objectId : uid
User.findOne({'_id' : self.id}, function(err, me){
for(var i=0; i<=me.friends.length; i++){
if (String(me.friends[i])==String(uid)){
me.friends.splice(i, 1);
break;
}
}
me.save(function(err,us){
next(err,'kljlmjk'+JSON.stringify(me));
});
});
Thanks for your response.
Issue Analytics
- State:
- Created 12 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
remove objects from array by object property - Stack Overflow
You can remove an item by one of its properties without using any 3rd party libs like this: var removeIndex = array.map(item =>...
Read more >Remove Object from an Array by its Value in JavaScript
Remove an Object from an Array by its Value using Array.slice() # ... To remove an object from an array by its value:...
Read more >Remove an Element from an Array by ID in JavaScript
Learn how to easily remove an object with a specified ID from an array in JavaScript.
Read more >Remove object from array of objects in Javascript - gists · GitHub
we have an array of objects, we want to remove one object using only the id property. const apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My ...
Read more >Removing Items from an Array in JavaScript - Ultimate Courses
To remove an item from array via its index, we'll first introduce the Array.prototype.splice method and then investigate a better pattern using ...
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
Don’t use splice.
Is there a way to do this to multiple documents as following?