0

I am inserting login tokens into my database, but I keep getting 'Error: key services.resume.appLoginToken.date must not contain '.' My code below is :

    if(!result.services.resume || result.services.resume.appLoginToken == null){
      var tokenStr = email + Math.random(1,100);
      tokenStr = Base64.encode(tokenStr);
      queryStr =  {
        "services.resume.appLoginToken.date": Date(),
        "services.resume.appLoginToken.base64Token": tokenStr
       };
       collectionUser.insert(queryStr, function(err, result) {
         if(err)
             {
                 console.log('Error:'+ err);
                 return;
              }
        });
     }

Any help would be great, thank you

suman j
  • 6,710
  • 11
  • 58
  • 109
kcuhcx2
  • 343
  • 1
  • 4
  • 15
  • have you tried `new Date()`? – gh0st Sep 12 '17 at 21:06
  • I get all the right values, its just when inserting into the collection that the error comes up – kcuhcx2 Sep 12 '17 at 21:08
  • 1
    `db.test.insert({services: {resume: {appLoginToken: {date: Date()}}}})` or just make your `queryStr` an object ie: `queryStr = { services: { resume: { appLoginToken: { date: Date(), base64Token: tokenStr }}}};` – gh0st Sep 12 '17 at 21:11
  • [Dot notation](https://docs.mongodb.com/manual/core/document/#dot-notation) is for "query" or "update". Insertion of data is a completely different thing. This seems to be the point you are not understanding. The naming of the variable as `queryStr` indicates this as well, since this is not a "query". – Neil Lunn Sep 12 '17 at 21:34
  • Hmm okay, do you believe I should just be updating my collection? – kcuhcx2 Sep 12 '17 at 22:08
  • Ended up getting it with using update and $set, cheers. – kcuhcx2 Sep 12 '17 at 22:19
  • I thinks is the same problem: https://stackoverflow.com/questions/12397118/mongodb-dot-in-key-name You are trying to insert object keys with dots: "services.resume.appLoginToken.date" Should be something like "services_resume_appLoginToken_date" – Ricardo Gamboa Sep 12 '17 at 23:57

0 Answers0