0

I'm trying to use the function print in "NoSQL Manager for MongoDB 4.9.10.2" to print the first element of an array. I'm trying to do the following:

    var start = ISODate("2018-12-18T03:00:00.000Z"); 
var end = ISODate("2018-12-19T02:59:59.000Z"); 

db.moicaTickets.aggregate([

    { $match : 
        { asunto:{$exists:true},
          asunto: {$ne:null},
          tiempos:{$exists:true}, 
          tiempos: {$ne:null},
          problemas:{$exists:true},
          creado:{$exists:true}, 
          "creado.lastEvent_tc": { $gt: start, $lt: end } }},
    { $project: 
        { pFecha: { $dateToString: { format: "%Y-%m-%d", date: "$creado.lastEvent_tc", timezone: "-03:00" } }, 
        asunto: 1, 
        tiempos: 1, 
        nroTkt: 1,
        losProblemas: { $arrayElemAt: ["$problemas",0]},
        primerProblema: "$losProblemas.nombre",
        primera: { $arrayElemAt: ["$tiempos",0]}}},
    { $addFields: { "lacola":{ "$toObjectId": "$primera.cola" }}},
    { $lookup:
       {
         from: "moicaTicketsColas",
         localField: "lacola",
         foreignField: "_id",
         as: "nombreCola"
         }}

         ]).forEach(function(doc){
         print(doc.nroTkt+";"+doc.nombreCola.0.arbol+";"+doc.pFecha+";"+doc.asunto.titulo+";"+doc.primerProblema);
})

But i get the next error:

2018-12-19T12:00:06.660-0300 E QUERY    [js] SyntaxError: missing ) after argument list @(shell):29:44
3
  • 1
    show all QUERY . Commented Dec 19, 2018 at 15:53
  • I added the whole query. Thanks! Commented Dec 19, 2018 at 16:29
  • This is an example of "nombreCola": "nombreCola" : [ { "_id" : ObjectId("5b55f8a351b9979f1e417b43"), "nombre" : "Al. Fuentes", "padre" : "5ad8a36251b99792eb60418a", "nivel" : 2, "creado" : { "creador" : "gerodriguez", "lastEvent_st" : "23-07-2018 12:47:47", "lastEvent_ts" : 1532360867, "lastEvent_tc" : ISODate("2018-07-23T15:47:47.377Z") }, "arbol" : "Ceop - Noc - Al. Fuentes" } ] Commented Dec 19, 2018 at 17:08

1 Answer 1

1

I solved it, what goes outside the query is JavaScript, so the proper way to print an array (or in this case, get the first element) is:

print(doc.nroTkt+";"+doc.nombreCola[0].arbol+";"+doc.pFecha+";"+doc.asunto.titulo+";"+doc.primerProblema);

Thank you!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.