find command to create "Virtual Field"

0

Context

I have a collection called "request" one of the properties is called body (in the format string). The content of the body is a json with a property called "date".

What do I need to solve?

To filter all docs with a date greater than 04.05.2018, for these docs (filtered), create a property in the collection "request" called true.

How would you do in SQL

It would create a virtual field separating the date from the rest of the string and based on this virtual field would make the date filter, based on this subquery, would create the UPDATE.

What did I do in Mongo Shell?

  •   db.getCollection("requisicao").find(
          { 
          }, 
          { 
            "requisicao._id" : "$requisicao._id", 
            "requisicao.hash" : "$requisicao.hash", 
            "requisicao.body" : "$requisicao.body", 
            "requisicao.resposta" : "$requisicao.resposta", 
            "requisicao.data" : "$requisicao.data"
          }
      );
    

    Object format saved in MongoDB.

     { 
    "_id" : ObjectId("5b0852ab080e6735c8dc0a46"), 
    "hash" : "andtM2tqTjA1VUhMRjc0ZlR3OHNxTE52SU43MCtBVXhoRGlwd1N4enhPd1N3aFpDVFBrN0hONjZBc0JHTldmNjBMb0wvMTJOTTUvUEdYWnpscUsxU1NubnprekVjVkNYS3lZbW9ZTGhRdEUrZmhaQXBYenU0Qkt==", 
    "body" : "{\r\n\t\"codCpfCnpj\": \"36886536880\",\r\n\t\"nota\": 501.0,\r\n\t\"date_nota\": \"2017-08-03T00:00:00\",\r\n\t\"nu_item\": \"MOO\",\r\n\t\"ti_segmento\": 5.0,\r\n\t\"va_venda\": 50000.0,\r\n\t\"conta\": \"\",\r\n\t\"chassi\": \"\"\r\n}", 
    "resposta" : false, 
    "data" : "25/05/2018 15:11:58"
     }
    

    The data is fictitious but the structure is the same

    Error

    Attempting to run this command I already have an error message.

    Mongo Server error (MongoQueryException): Query failed with error code 9 and 
    error message 'Syntax error, incorrect syntax near '21'.' on server XPTO
    

    Question:

    What am I doing wrong? Any suggestions for troubleshooting?

        
  • asked by anonymous 06.06.2018 / 19:01

    0 answers