rwynn / monstache-site

documentation for the monstache project
https://rwynn.github.io/monstache-site/
MIT License
22 stars 31 forks source link

findId not found? #15

Closed xiangyiliu18 closed 5 years ago

xiangyiliu18 commented 5 years ago

I got oneissure about findId. Please tell me what do i need to figure it out

INFO 2019/05/08 17:07:20 Started monstache version 3.24.2 INFO 2019/05/08 17:07:20 Successfully connected to MongoDB version 4.0.9 INFO 2019/05/08 17:07:20 Successfully connected to Elasticsearch version 2.3.1 INFO 2019/05/08 17:07:20 Listening for events INFO 2019/05/08 17:07:20 Sending systemd READY=1 WARN 2019/05/08 17:07:20 Systemd notification not supported (i.e. NOTIFY_SOCKET is unset) INFO 2019/05/08 17:07:20 Watching changes on collection firewall.questions ERROR 2019/05/08 17:07:20 Error in function findId: not found

Anther issue is: if i did not use script. my data in db and elasticsearch are exactly same. If i use the script, i will miss two fields, like user. and got null for empty array

xiangyiliu18 commented 5 years ago

my scripts: [[script]] namespace = "firewall.questions" script = """ module.exports = function(doc){ if(doc.user){ doc.user = findId(doc.user, { database: "firewall", collection: "user" }) } doc.answer_count = doc.answers.length; doc.viewcount = doc.viewers.length; doc.score = doc.upvote.length - doc.downvote.length; return .omit(doc,"viewers", "answers", "upvote", "downvote"); } """

  1. with script: "answer_count" : 0, "body" : "fdsf", "id" : "in2660Hkm", "media" : null, "score" : 0, "tags" : [ "fsdaf" ], "timestamp" : 1557334783, "title" : "antoerh", "user" : "5cd3073e5fcc1b02af1f953f", "view_count" : 0
  2. without script: "__v" : 0, "answer_count" : 0, "body" : "fdsf", "id" : "in2660Hkm", "media" : [ ], "score" : 0, "tags" : [ "fsdaf" ], "timestamp" : 1557334783, "title" : "antoerh", "user" : "5cd3073e5fcc1b02af1f953f", "view_count" : 0, "answers" : [ ], "upvote" : [ ], "viewers" : [ ], "downvote" : [ ], "accepted_answer" null }
rwynn commented 5 years ago

findId returns a document if it's found in the given database/collection and null if it is not found. I think you are seeing that the document is not found in the collection and null is being returned and set into the document for indexing.

xiangyiliu18 commented 5 years ago

yes. you are right. I got user right now, but how can i keep the field with null value or empty array