Greetings! I am currently developing an application that utilizes a MongoDB database. Within this database, there exists a user collection where all user data is stored. The structure of a document in this collection is as follows:
{
"_id" : ObjectId("542e67e07f724fc2af28ba75"),
"id" : "",
"email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="204c5549474960474d41494c0e43 ...",
"tags" : [
{
"tag" : "Paper Goods:Liners - Baking Cups",
"weight" : 2,
"lastInsert" : 1412327492874
},
...
]
}
In addition to the user collection, I have created a recommendation.tagsMatch collection to store the similarities between different tags. A document within this collection has the following format:
{
"_id" : "Fish:Swordfish Loin Portions-Paper Goods:Lialberto- Baking Cups",
"value" : {
"tag1" : "Fish:Swordfish Loin Portions",
"tag2" : "Paper Goods:Lialberto- Baking Cups",
"sum1" : 3,
"sum2" : 1,
"sumQ1" : 9,
...
}
}
The next step involves implementing a mapReduce process from documents in recommendation.users
to documents in recommendation.tagsMatch
. If it's the first time running the document, the value.count
field should be set to 0; otherwise, it should retain its previous value.
To achieve this, I have created a mapReduce function as shown below:
var f1 = function() {
...
var r1 = function(key, values) {
...
};
I execute the mapReduce command using the following statement:
db.recommendation.users.mapReduce(f2, r1,{query: {}, "out": "recommendation.tagsMatch"}).
However, upon execution, an error is encountered:
2014-10-27T17:01:28.923+0100 map reduce failed:{
"errmsg" : "exception: ReferenceError: db is not defined near 'ntValue = db.recommendation.tagsMatch.fin' (line 11)",
"code" : 16722,
"ok" : 0
}
I'm seeking assistance regarding this issue. How can I rectify this error?