[
{lecture : "427#Math"},
{lecture : "217#Science"},
{lecture : "7#History"},
{lecture : "12#Music"}
]
Suppose I have the database structure above. I want to return only the lecture code. What have i done so far?
db.collection.aggregate([
{$project: {"lecture": {$split: ["$lecture" , "#"]}}}
])
But it comes back as a collection ["427" , "Math"]. How can I return only the lecture code, which is the part that precedes the character #.
source
share