REST wrapper around mongoose -> mongoosastic -> elastic
231
mongoosastic supported es-7 now. So docs may be not actual.
docker pull sarafanfm/mongoosastic-rest
Fastify based HTTP REST API wrapper around mongoose with mongoosastic plugin and node-cron as elasticsearch reindex scheduler.
See examples stack and config
GET /db/collection/:_idGet doc by id.
See below about GET params
POST | PUT | DELETE /db/collection/:_idCreate 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/:_idModify 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/collectionGet (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/_aggregateMongoose aggregate behavior. Send pipeline array in body
POST /db/collection/_searchPass mongoosastic search first param into body.
You can pass _options object key if second param required.
POST /db/collection/_essearchPass mongoosastic esSearch first param into body.
You can pass _options object key if second param required.
GET paramsYou can pass comma separated fields list to be selected into select GET param. See Mongoose docs
GET /db/collection/someid?select=firstName,age
For sorting, limits, etc, pass serialized JSON object into options GET param. See Mongoose docs
GET /db/collection/someid?options={"limit":50}
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"}}]
Content type
Image
Digest
Size
61.1 MB
Last updated
almost 6 years ago
docker pull sarafanfm/mongoosastic-rest