This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 New App',another:'things'}]; | |
// get index of object with id of 37 | |
const removeIndex = apps.findIndex( item => item.id === 37 ); | |
// remove object | |
apps.splice( removeIndex, 1 ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj = { | |
a: { | |
b: { | |
c: 12 | |
} | |
}, | |
findPath :function (str) { | |
let x = str.split('.'); | |
let ans = null; | |
for(let i = 0; i<= x.length - 1; i++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 | |
I was having same problem with my title and after lots of searching, i found this answer Here, | |
var search = 'Joe'; | |
db.users.find(name: /^search/) | |
db.users.find(name: {$regex: /^search/}); | |
db.users.find(name: {$regex: "/^" + search + "/"}); | |
The queries above won’t return anything. The solution to this little problem is quite simple: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.removeDuplicates = async (req, res) => { | |
let keywordlist = await Keyword.find(); | |
/**get list */ | |
for (let i = 0; i < keyword.length; i++) { | |
let singlekeyword = keywordlist[i]; | |
/**get similar keyword without currentone */ | |
let similarKeywords = await Keyword.find({ | |
$and: [ | |
{ keyword: new RegExp(singlekeyword.keyword, "i") }, | |
{ _id: { $ne: singlekeyword._id } }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let timeline = await Timeline.aggregate([ | |
// { $match: { timelineTopic: timelineTopic } }, | |
// { | |
// $group: { | |
// _id: "$date", | |
// shortDescription: { $addToSet: "$shortDescription" }, | |
// longDescription: { $addToSet: "$longDescription" }, | |
// articles: { | |
// $push: "$article", | |
// }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let timelines = await Timeline.find({ | |
timelineTopic: timelineTopic, | |
}).populate({ | |
path: "articles", | |
populate: { | |
path: "publisher", | |
model: "Publisher", | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.getkeywordswithSkippingKeywords = async (req, res, next) => { | |
try { | |
const userId = req.userData.userId; | |
const limit = parseInt(req.params.limit); | |
const page = parseInt(req.params.page); | |
let keywords = await Keyword.aggregate([ | |
{ $match: {} }, | |
{ $sort: { count: -1 } }, | |
{ $skip: limit * page }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getPreferencesForLoggedinUser = async (req) => { | |
let userId = req.userData.userId; | |
let result = await Preference.aggregate([ | |
{ $match: { user: mongoose.Types.ObjectId(userId) } }, | |
{ | |
$lookup: { | |
from: Keyword.collection.name, | |
localField: "keyword", | |
foreignField: "_id", | |
as: "keywordData", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pref = await Preference.aggregate([ | |
{ $sort: { _id: -1 } }, | |
{ | |
$facet: { | |
user: [ | |
{ | |
$lookup: { | |
from: User.collection.name, | |
localField: "user", | |
foreignField: "_id", |