3

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

First I tried A.find({where: {collection_of_B: {contains: B_ID}}}) which didn't return what I wanted. Then I found a stackoverflow post saying that this type of query was not currently possible with waterline and that a native query to mongodb should be used instead. This brings me to my question as I first thought that a 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 to find 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 on the mongo document when I printed it to terminal.

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

Community
  • 1
  • 1
John Pertoft
  • 1,045
  • 1
  • 9
  • 17
  • I looked in the database directly and apparantly waterline creates a separate "table" (mongo collection) for the collection type. But I dont have access to it as a waterline model so the second part of the question still stands. – John Pertoft Aug 03 '15 at 13:02

0 Answers0