Questions tagged [monk]

Monk is a tiny layer that provides some usability improvements for MongoDB usage within Node.JS

Features (taken from monks github page):

  • Command buffering. You can start querying right away.
  • Promises built-in for all queries. Easy interoperability with modules.
  • Easy connections / configuration
  • Well-designed signatures
  • Improvements to the MongoDB APIs (eg: findAndModify supports the update signature style)
  • Auto-casting of _id in queries
  • Builds on top of mongoskin
  • Allows to set global options or collection-level options for queries. (eg: safe is true by default for all queries)

Connection

var db = require('monk')('localhost/dbname');

To set global multi-doc at db level

db.options.multi = true;

To set global multi-doc at collection level

db.get('users').options.multi = false;  

Close DB connection

db.close(); 

Operations

var collection = db.get('collection');    
collection.insert({ }, function(err) { });
collection.find({ }, function(err, docs) { });
collection.findOne({ }, function(err, doc) { });
collection.update({ }, { }, function(err, docs) { });
collection.findAndModify({ }, { }, function(err, docs) { });
collection.findById('id', function(err, doc) { });
collection.drop(function(err) { });

Index

collection.index('name.first', function() { });
Unique Index
collection.index('email', { unique: true });  
Compound Index
collection.index('name.first name.last')   
Compound with sort
collection.index({ 'email': 1, 'password': -1 }); 
To get indexes for a collection
collection.indexes(fn);
Drop an index
collection.dropIndex(name, fn);
Drop all indexes
collection.dropIndexes(fn);
184 questions
0
votes
1 answer

Failed to load c++ bson extension, using pure JS version when using monk to access Mongodb

When I want to use monk as a middleware to access the mongodb, it prompts that Failed to load c++ bson extension, using pure JS version My running evn is the following: OS X Yosemite Node v0.10.32 npm 1.4.28 Mongodb 2.6.5 monk 0.9.1 Does any of…
user3291001
  • 1,969
  • 1
  • 11
  • 3
0
votes
2 answers

Issue in inserting multiple documents (Bulk Insert) into a mongoDB collection using monk in Node.JS?

I am trying to insert multiple documents into a collection in mongoDB database, but am only getting only one object ID as response (multiple documents are getting created in the DB). Code: exports.createRelation = function(relationDoc, db,…
Ameen Rashad
  • 514
  • 6
  • 17
0
votes
0 answers

Can't update document using MongoDb and Monk

I'm trying to do a simple document update using Monk however the following exception gets thrown: .../node_modules/monk/node_modules/mongoskin/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js:35 throw new Error("Argument passed in…
Ignas
  • 1,965
  • 2
  • 17
  • 44
0
votes
1 answer

Trouble using mongodb $ positional indicator in nodejs with monk.js

I am trying to perform a search on my database and return the roles a user has for an application and store that in their session. The end state being in their session I now have user.applications = [ { "_id": "oehgf12083310f1h30f", …
Reece
  • 714
  • 2
  • 9
  • 24
0
votes
1 answer

Sorting MongoDB collection and saving to another collection

I am trying to sort a collection by highest number in a field to lowest and save to another collection. I am using monk to connect to the DB.
0
votes
4 answers

Koa and Passport with MongoDb

I'm having some troubles with Koa, Passport and Monk. I'd like to have a simple local authentication with Passport. I've followed some tutorials and got as far as this: (auth.js) const passport = require('koa-passport'), LocalStrategy =…
QlliOlli
  • 637
  • 3
  • 13
  • 25
0
votes
1 answer

Code stalling at collection.find

I am new to JS and am stuck at this point. I am trying to clear my DBs before starting a new query and it keeps stalling at the collection.find command. If I removed the code to clear the DB everything works fine. router.get('/parse', function(req,…
0
votes
0 answers

Getting the size of a list of mongo collection using MEAN+monk stack

Is there any way to obtain the size (count) of a list of mongodb collection using the following stack : nodejs+express+mongodb+monk I went thus far before getting lost in forest of promises. EDIT : was on mobile stackoverflow, here's the code. Note…
bluearth
  • 501
  • 4
  • 18
0
votes
1 answer

How to loop over mongodb array with express and monk to create a page for each element?

I am building a web app with express, nodejs and monk. I am trying to create a page for each element of an array in my mongodb database. That data is already in the collection called collections with the key coll_list like so: { "_id" :…
Colin Riddell
  • 407
  • 4
  • 17
0
votes
1 answer

node/mongodb - how to store queries' results

I'm using Express.js and I have this simple router router.get('/', function(req, res) { var userlist; req.db.get("usercollection").find({},{}) .success(function(docs){ userlist = docs; }); res.render('index',…
user3264316
  • 332
  • 3
  • 18
0
votes
2 answers

Promises in a for loop, do something when done

Basically, I'm trying to figure out a way to do a bunch of queries in a for loop and then do something once they've all completed. I got it to work, but only because I used this great library that wraps all of mongodb with promises. var mongo =…
Nick Lang
  • 469
  • 6
  • 16
0
votes
1 answer

Why isn't my Node script exiting? (utilising Monk)

I'm writing a library to abstract my data layer (it's going to use a mix of Mongo and Memcached). I've been testing Monk and can't figure out why the below script isn't finishing: mongo =…
Ryan Brodie
  • 6,554
  • 8
  • 40
  • 57
0
votes
1 answer

How to create unique id in nested array

I have the following collection example: { _id: 'asdfjklsfo', name: 'My name', sections: [ { title: 'my title' }, { title: 'second title' } ] } And I want all the sections to have a unique id so that I can easily…
Catfish
  • 18,876
  • 54
  • 209
  • 353
-1
votes
2 answers

Don't GET req.query.name to collection.find in express and MongoDB

I use a mongodb database where I have its internal log data. With Express, Node and Monk (following this guide) I have to try to get data from a search text box, and I stopped on how to request this data. from the userlist.ejs page I have…
scofx
  • 149
  • 12
-1
votes
1 answer

How can I bundle MONGODB?

I'm try to bundle with browserify when I try browserify index.js > main.js I get this error Error: Can't walk dependency graph: Cannot find module 'mongodb-client-encryption' from…
user14800938
1 2 3
12
13