Small and injectable mongodb utils!
$ npm i --save mongo-utils
// 1. Reduce Array of Strings to String: prop = ["Sambhav", "Jain"] --> prop = "Sambhav, Jain"
const { reduceMongoArrayToString } = require("mongo-utils");
db.model.aggregate([
{
$project: {
prop: reduceMongoArrayToString("prop"),
},
},
]);
// 2. Cast String to Number while comaparing in query:
// prop2 = "30", query = Find all records with prop2 >= 10
const { castStringToNumberInQuery } = require("mongo-utils");
db.model.find({ prop2: castStringToNumberInQuery("$gte", "Int", "prop2") });
// Caveat: Property under comparison must have numeric value stored as String for this to work