• Stars
    star
    315
  • Rank 132,951 (Top 3 %)
  • Language
    Go
  • Created over 11 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MongoDB generic REST server in Go

Mora - Mongo Rest API

REST server for accessing MongoDB documents and meta data

Documents

When querying on collections those parameters are available:

query  - use mongo shell syntax, e.g. {"size":42}
limit  - maximum number of documents in the result
skip   - offset in the result set
fields - comma separated list of (path-dotted) field names
sort   - comma separated list of (path-dotted) field names
extended_json - set to "true" to return responses in [MongoDB Extended JSON](http://docs.mongodb.org/manual/reference/mongodb-extended-json/) format
Examples
Listing aliases
$ curl 'http://127.0.0.1:8181/docs/' \
>   -D - \
>   -H 'Accept: application/json'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 07:06:30 GMT
Content-Length: 61

{
  "success": true,
  "data": [
   "test",
   "local"
  ]
}
Listing databases
$ curl 'http://127.0.0.1:8181/docs/local/' \
>   -D - \
>   -H 'Accept: application/json'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 07:07:11 GMT
Content-Length: 61

{
  "success": true,
  "data": [
   "local",
   "use1"
  ]
}
Listing collections
$ curl 'http://127.0.0.1:8181/docs/local/local' \
>   -D - \
>   -H 'Accept: application/json'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 07:24:10 GMT
Content-Length: 98

{
  "success": true,
  "data": [
   "new-collection",
   "startup_log",
   "system.indexes"
  ]
}
Inserting document
$ curl 'http://127.0.0.1:8181/docs/local/local/new-collection/document-id' \
-D - \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data '{"title": "Some title", "content": "document content"}'

HTTP/1.1 201 Created
Content-Location: /docs/local/local/new-collection/document-id
Content-Type: application/json
Date: Tue, 22 Apr 2014 07:23:33 GMT
Content-Length: 116

{
  "success": true,
  "data": {
   "created": true,
   "url": "/docs/local/local/new-collection/document-id"
  }
}
Finding document
$ curl 'http://127.0.0.1:8181/docs/local/local/new-collection/document-id' \
>   -D - \
>   -H 'Accept: application/json'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 07:32:33 GMT
Content-Length: 123

{
  "success": true,
  "data": {
   "_id": "document-id",
   "content": "document content",
   "title": "Some title"
  }
}
Finding documents
$ curl 'http://127.0.0.1:8181/docs/local/local/new-collection?limit=1&skip=1' \
>    -D - \
>    -H 'Accept: application/json'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 23 Apr 2014 23:18:39 GMT
Content-Length: 387

{
  "success": true,
  "prev_url": "/docs/local/local/new-collection?limit=1\u0026skip=0",
  "next_url": "/docs/local/local/new-collection?limit=1\u0026skip=2",
  "data": [
   {
    "_id": "535849cfb734f91cdc000002",
    "content": "document content",
    "title": "Some title"
   }
  ]
}
Updating document
$ curl 'http://127.0.0.1:8181/docs/local/database/new-collection/document-id' \
>  -D - \
>  -X PUT \
>  -H 'Content-Type: application/json' \
>  -H 'Accept: application/json' \
>  --data '{"title": "New title"}'
HTTP/1.1 200 OK
Content-Location: /docs/local/database/new-collection/document-id
Content-Type: application/json
Date: Tue, 22 Apr 2014 06:37:02 GMT
Content-Length: 133

{
  "success": true,
  "data": {
   "created": false,
   "url": "/docs/local/database/new-collection/document-id"
  }
}
Updating documents
$ curl 'http://127.0.0.1:8181/docs/local/local/new-collection' \
>   -D - \
>   -X PUT \
>   -H 'Content-Type: application/json' \
>   -H 'Accept: application/json' \
>   --data '{"$set": {"title": "New title"}}'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 23 Apr 2014 23:33:11 GMT
Content-Length: 22

{
  "success": true
}
Removing document
$ curl 'http://127.0.0.1:8181/docs/local/local/new-collection/document-id'  \
>   -D - \
>   -X DELETE \
>   -H 'Accept: application/json'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 07:42:47 GMT
Content-Length: 22

{
  "success": true
}
Removing collection
$ curl 'http://127.0.0.1:8181/docs/local/local/new-collection'  \
>   -D - \
>   -X DELETE \
>   -H 'Accept: application/json'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 07:43:24 GMT
Content-Length: 22

{
  "success": true
}
Statistics
Database statistics
$ curl http://127.0.0.1:8181/stats/local/local -D -
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 08:17:46 GMT
Content-Length: 341

{
  "success": true,
  "data": {
   "avgObjSize": 595.6,
   "collections": 3,
   "dataFileVersion": {
    "major": 4,
    "minor": 5
   },
   "dataSize": 5956,
   "db": "local",
   "fileSize": 67108864,
   "indexSize": 0,
   "indexes": 0,
   "nsSizeMB": 16,
   "numExtents": 3,
   "objects": 10,
   "ok": 1,
   "storageSize": 10502144
  }
}
Collection statistics
$ curl http://127.0.0.1:8181/stats/local/local/startup_log -D -
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 22 Apr 2014 08:18:16 GMT
Content-Length: 389

{
  "success": true,
  "data": {
   "avgObjSize": 728,
   "capped": true,
   "count": 8,
   "indexSizes": {},
   "lastExtentSize": 10485760,
   "max": 9223372036854775807,
   "nindexes": 0,
   "ns": "local.startup_log",
   "numExtents": 1,
   "ok": 1,
   "paddingFactor": 1,
   "size": 5824,
   "storageSize": 10485760,
   "systemFlags": 0,
   "totalIndexSize": 0,
   "userFlags": 0
  }
}

Install from source

go get -u github.com/emicklei/mora

Create a release

sh release.sh

Configuration

Mora uses a simple properties file to specify host,port,aliases and other options

# listener info is required
http.server.host=localhost
http.server.port=8181

# enable cross site requests
http.server.cors=true

# for swagger support (optional)
swagger.path=/apidocs/
swagger.file.path=./swagger-ui/dist

# mongo instances are listed here; specify an alias for each
mongod.{alias}.host=localhost
mongod.{alias}.port=27017
# initial and operational timeout in seconds
mongod.{alias}.timeout=5
# optional authentication
mongod.{alias}.username=
mongod.{alias}.password=
mongod.{alias}.database=
# read preference mode
# supported options (case-insensitive): https://godoc.org/gopkg.in/mgo.v2#Mode
mongod.{alias}.mode=primary
# alternatively, a mongodb connection string uri can be used instead
# supported options: https://godoc.org/gopkg.in/mgo.v2#Dial
mongod.{alias}.uri=mongodb://myuser:mypass@localhost:40001,otherhost:40001/mydb

# enable /stats/ endpoint
mora.statistics.enable=true

Run

$ mora -config mora.properties

Swagger

Swagger UI is displaying automatically generated API documentation and playground.

Swagger UI

© 2013, http://ernestmicklei.com. MIT License

More Repositories

1

go-restful

package for building REST-style Web Services using Go
Go
4,871
star
2

proto

parser for Google ProtocolBuffers definition
Go
577
star
3

dot

Go package for writing descriptions using the Graphviz DOT and Mermaid language
Go
268
star
4

hopwatch

webbased debugging for Go programs
Go
258
star
5

melrose

interactive programming of melodies, producing MIDI
Go
179
star
6

go-restful-openapi

OpenAPI extension in Go for the go-restful package
Go
133
star
7

forest

REST Api Testing package for writing integration tests in Go
Go
123
star
8

hazana

package to build load tests for services (http, gRPC, tcp) by implementing an Attacker
Go
73
star
9

zazkia

tcp proxy to simulate connection problems
Go
69
star
10

rango

a REPL program for the Go language
Go
56
star
11

go-restful-swagger12

Swagger 1.2 extension to the go-restful package
Go
50
star
12

rendersnake

Java library for creating components and pages that produce HTML using only Java
Java
36
star
13

gmig

Google Cloud Platform migrations tool for infrastructure-as-code
Go
27
star
14

proto-contrib

contributed tools and other packages on top of the Go proto package
Go
24
star
15

pgtalk

generics package and code generator to access PostgreSQL tables and views on top of pgx
Go
20
star
16

protobuf2map

Decoder for a ProtocolBuffers message that produces a Go map[string]interface{}
Go
15
star
17

eventbus

Eventbus, a lightweight in-app event communication bus for Go
Go
15
star
18

gws

command line tool for using the Google Workspace Admin (formerly GSuite)
Go
14
star
19

swagger2

Go implementation of the Swagger 2.0 specification
Go
12
star
20

v8dispatcher

Go package that adds a message layer on top of v8worker (binding for the Javascript V8 engine)
Go
11
star
21

critter

http proxy for testing purposes
Java
9
star
22

licenser

tool to put a copyright notice header in source files
Go
9
star
23

landskape

general purpose webservice for the registation of applications and their connections
Go
8
star
24

renderbee

package for creating HTML renderable components in Go
Go
8
star
25

artreyu

simple tool for artifact management
Go
7
star
26

validate

simple validation library for Go
Go
7
star
27

parzello

Parzello is a delay and retry service on top of Google Pub Sub to publish messages with a time delay to a topic.
Go
6
star
28

karina

realtime image-resizing service in Go
Go
6
star
29

go-selfdiagnose

package for health checking a Go application (simplified port of its Java implementation)
Go
6
star
30

tviewplus

package that adds extra components to build Terminal applications on top of https://github.com/rivo/tview
Go
5
star
31

talks

public collection of presentations about different topics using different tools and languages
Go
5
star
32

https-proxy

https reverse proxy (with x-forwarded-* headers)
Go
4
star
33

xconnect

exploring network connectivity in a microservice landscape
Go
4
star
34

genika

collection of code generation tools
Go
4
star
35

mxgraph

package in Go for writing mxgraph XML models
Go
3
star
36

tokenman

small Go library for JWT token management
Go
3
star
37

gcloudx

extra features for accessing the Google Cloud Platform
Go
3
star
38

go-bitbucket

client package to access the bitbucket.org REST api 2.0
Go
3
star
39

tre

Go package for tracing an error in the call stack
Go
3
star
40

graphql-client-gen

A schema-driven GraphQL zero-dependencies client generator for Go
Go
3
star
41

simone

package for building backends to simone_fui
Go
2
star
42

hazana-grafana-monitoring

Hazana extension that sends metrics to Graphite during the execution of the load test
Go
2
star
43

gioui-mdi

experiment with MDI support for Gio UI
Go
2
star
44

dollar

The $1 Unistroke Recognizer (Go version)
JavaScript
2
star
45

zenna

Go packages for 2D and 3D scenes and animations, to render by external programs. (Port from my older Smalltalk packages PhilemonSmallScript3D and Zenna)
Go
2
star
46

assert

writing unit tests should be simple, require minimal effort and be helpful in explaining why they fail
Go
2
star
47

dgraph-access

helper package on top of the official Go client for DGraph
Go
2
star
48

dgraph-parser

DGraph schema parser
Go
1
star
49

atlas

Atlassian provisioning tool
Go
1
star
50

gdep

tool to explore dependencies of resources in the Google Cloud Platform
Go
1
star
51

gspeech

simple tool that uses the Text-to-Speech API in the Google Cloud Platform
Go
1
star
52

log15-stackdriver-handler

logging handler for log15 that uses the StackDriver Logging API of the Google Cloud Platform
Go
1
star
53

moqi

mgo query interceptor (mgo is the MongoDB driver for the Go language)
Go
1
star
54

gcppub

additional tooling for Google Cloud Pub/Sub
Go
1
star
55

artreyu-nexus

plugin for artreyu, tool for artifact assemly, that uses a Sonatype Nexus repository
Go
1
star
56

xconnect-store

microservice for persisting xconnect configurations
Go
1
star
57

melrose-osx

build scripts to create a Mac OSX package
Makefile
1
star
58

kiya-webapp

Web UI for kiya for GCP deployment
Go
1
star
59

minio-probe

minio / probe - a simple mechanism to trace and return errors in large programs.
Go
1
star
60

htmllog

a simple logger that safely produces an append-only, auto-scrolling-on-refresh HTML file.
Go
1
star
61

artreyu-google-cloud-storage

plugin for artreyu, an artifact assembly and storage tool
Go
1
star
62

v8worker-docker

Dockerfile for building v8worker based applications
1
star
63

tank

Java
1
star
64

selfdiagnose

a Java library of diagnotistic tasks that can verify the availability of external resources required for the execution of a J2EE application.
Java
1
star
65

nanny

Records a sliding window of Go slog events with all attribute values for remote inspection through HTTP.
Go
1
star