feathers-mongo-collections works just like a standard FeatherJS service, except for the get/findOne. It uses the collection name as the
id value when performing
npm install feathers-mongo-database --save
To create an instance of a
feathers-mongo-collections service, first connect to your MongoDB database. Then pass the connected database into
var feathers = ;var feathersMongoColls = ;var MongoClient = MongoClient;var dbAddress = 'mongodb://localhost:27017/feathers-tuts';// Prep the Feathers server.var app =;// Connect to the database.MongoClient;// Start the server.var port = 8081;app;
find() currently accepts no parameters. It simply returns an array of all of the collections in the connected db. It returns data in this format:
Provide a collection
create is successful, the data returned will look like this:
If the collection already exists, the existing collection will not be overwritten. MongoDB doesn't actually require creating a collection before inserting a document. If you insert a document into a collection that doesn't exist, the collection will be created upon insert, so this method is mostly a convenience method for web apps.
For update operations, the collection name replaces the REST id. Pass the current db name as the id, and the new name in the data.
PUT /api/localhost:27017/feathers-tuts/_collections/MyCollection HTTP/1.1 Content-Type: application/x-www-form-urlencoded name=NewCollectionName
If the update operation is successful, the response will look like this:
If the name / id doesn't exist, the following MongoDB error will be returned:
"exception: source namespace does not exist"
If the target name already exists, the following MongoDB error will be returned:
"exception: target namespace exists"
For remove operations, the collection name is used as the REST id.
Successful remove operations will return
If the named collection cannot be found, the following MongoDB error will be returned:
"ns not found"