Sign inSign up

sarafanfm/mongoosastic-rest

By sarafanfm

•Updated almost 6 years ago

REST wrapper around mongoose -> mongoosastic -> elastic

Image
0

231

sarafanfm/mongoosastic-rest repository overview

⁠Elasticsearch 7

mongoosastic⁠ supported es-7 now. So docs may be not actual.

⁠mongoosastic-rest

docker pull sarafanfm/mongoosastic-rest

Fastify⁠ based HTTP REST API wrapper around mongoose⁠ with mongoosastic⁠ plugin and node-cron⁠ as elasticsearch reindex scheduler.

⁠Configuration

See examples stack⁠ and config⁠

⁠Routes

⁠GET /db/collection/:_id

Get doc by id.

See below⁠ about GET params

⁠POST | PUT | DELETE /db/collection/:_id

Create or replace or delete doc by id. Pass doc into body (excluding DELETE of course). Batch insert are supported, just pass array of docs to POST body.

⁠PATCH /db/collection/:_id

Modify doc by id. Pass changes into body. You can skip $set key for plain fields:

e.g.

{
  "firstName": "Alex", // Will change firstName
  "$push": {"posts": "somePostId"} // Push new post id into posts array field
}
⁠GET /db/collection

Get (filtered) list.

Pass mongoose Model find⁠ filter param as plain GET params.

E.g.: firstName=Max&age=25.

If you need other comparison operations (e.g. $ne null) you can pass serialized JSON object into filter GET param.

E.g.: filter={"age":{"$gt":25},"firstName":{"$ne":null}}.

Please use distinct query param if you need to one field array instead result docs:

GET /db/collection?distinct=_id will return array of _id but not docs.

See below⁠ about others GET params

⁠POST /db/collection/_aggregate

Mongoose aggregate⁠ behavior. Send pipeline array in body

⁠if esEnabled

⁠POST /db/collection/_search

Pass mongoosastic search⁠ first param into body. You can pass _options object key if second param required.

⁠POST /db/collection/_essearch

Pass mongoosastic esSearch⁠ first param into body. You can pass _options object key if second param required.

⁠That's all :)

⁠GET params

⁠select

You can pass comma separated fields list to be selected into select GET param. See Mongoose docs⁠

GET /db/collection/someid?select=firstName,age

⁠options

For sorting, limits, etc, pass serialized JSON object into options GET param. See Mongoose docs⁠

GET /db/collection/someid?options={"limit":50}

⁠populate

You can use mongoose populate⁠ behavior. Pass field name into populate GET param.

model Comment: { author: { type: ObjectId, ref: 'User' } }

query: GET /db/comments/someid?populate=author

Filtering fields of populated docs (space separated here) (see mongoose docs⁠):

GET /db/comments/someid?populate={"path":"author","select":"firstName age -_id"}

Multiple and nested populate (comment author, related post and nested - post author):

GET /db/comments/someid?populate=["author", {"path":"post","populate":{"path":"author"}}]

Tag summary

Content type

Image

Digest

Size

61.1 MB

Last updated

almost 6 years ago

docker pull sarafanfm/mongoosastic-rest