Thursday 4 May 2017

Mongoose not retrieving the same data as mongo console client

So, I have a Mongo database with a collection where the documents have a structure similar to this:

{
  "name": "sampleName",
  "subdocument": [
      {
        "name": "subDocName",
        "subsubdocument": [...]
      }
  ]
}

When running mongoose it returns the subsubdocument array empty for all the documents even if they have data. If I run a mongo client on a console I can retrieve the information with no problem at all.

But it gets weirder: if I run the following on my nodejs endpoint it returns an empty array, suggesting there are no empty subsubdocument arrays in any of my documents (which I can confirm from a direct access to the database is true).

MyCollection.find({'subdocument.subsubdocument': {$eq: []}},function(err, result) {
  console.log(result);
});

Although if I run the code bellow all my subsubdocument arrays are printed as [ ].

MyCollection.find(function(err, result) {
  console.log(result);
});

I have even used a GUI (mongobooster) to check if I was not going crazy.

I have no clue of what is going on here and no idea how to solve this so please any ideas are welcome.

PS: I am using version 3.2 of MongoDB and mongoose v4.4.12.



via Victor Cerqueira

No comments:

Post a Comment