What is the translation of 'collection' type waterling with mongodb adapter?

I have a model (A) at the waterline with type 'collection' (which contains the IDs of other instances of model (B)). Then I would like to find all A records whose collection contains a specific identifier B.

At first I tried A.find({where: {collection_of_B: {contains: B_ID}}})

which didn't return what I wanted. Then I found a post on StackOverflow question which stated that this type of query is currently not possible with a waterline and that a custom query to mongodb should be used instead. This brings me to my question as I initially thought the collection would be translated to an array in mongo, but that doesn't seem to be the case.

I tried this query (based on mongodb documentation )

A.native(function(err, collection) {
  var cursor = collection.find({collection_of_B: B_ID});
  ....

      

But that didn't return anything either, and when I instead tested searching for documents based on a field that was just a string in my waterline model it worked as expected, but I also couldn't see the collection type in the mongo document when I printed it to the terminal.

So how is the waterline collection attribute type stored in mongodb? And how do I make a query to find records with a specific value in a collection?

+3


source to share





All Articles