Yhom Torke
Yhom Torke

Reputation: 161

Feathers.js mongoose querying

I'm very new to feathers.js, how would you accomplish querying for an object?

{
   ...,
   obj: {
      foo: 1,
      bar: 1
   },
   ...
}

The following seems to not work

/some-doc?obj['foo']['$eq']=1

Also, how would you tackle a query like checking a size of array

/some-doc?someArray['length']['$gt']=0

I've been trying to send param like

checkArray=true

Process it at before:find but no luck. Is this the right approach?

Thank you,

Upvotes: 3

Views: 1423

Answers (1)

Daff
Daff

Reputation: 44215

In general, most queries supported by Mongoose and MongoDB will work for your Feathers service. MongoDB queries on nested fields using the dot notation so it would be:

/some-doc?obj.foo=1

Length queries can be done with the $size operator. To check if an array has a certain length, you can use the dot notation to see if the entry at the index exists (see this answer):

/some-doc?someArray.1[$exists]=true

Upvotes: 2

Related Questions