How can we convert a numeric string to number in Mongodb?
Actual Problem:
Collection: try
Two Sample documents stored in try collection:
{
_id: "1"
testField: 150
}
{
_id: "A"
testField: 140
}
I want to filter out the _id field in the project phase for further processing in group phase. The query below is working fine but I need better solution for it like using type or any other method.
db.try.aggregate([{$match: {"_id":{$in:["1","2","3","4","5","6","7","8","9"]}}}, {$group:{"_id":0, total: {$sum:"$testField"}}}])
_iddb.try.find({"_id":{$type:2}}). As '_id' will be always string, it is not meaningful query. Can you provide more details please? Furthermore you can follow link docs.mongodb.org/manual/reference/operator/query/type$infor 1-9. Do you have only 9 records(as _id is unique) ?