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
2
votes
1 answer

node js monk update lingers

I'm new to node.js, mongoDB, monk and express (All on the latest versions). and as I'm working I encountered the next situation: I have a table that is updated, and I read from it periodically. When I read from it, I update a flag in the database,…
Nur Bar
  • 731
  • 2
  • 8
  • 16
2
votes
0 answers

MongoDB $elemMatch projection ignored

I am using Node.js, Koa, MongoDB, Monk. When I use $elemMatch in query, it works fine but in projection it is getting ignored. I have data like this { _id: 1, zipcode: "63109", students: [ { studentId: "1", name: "john", school:…
2
votes
1 answer

does mongodb insert creates new schema

i got an existing mongoDB server that is already running and storing data,lets say it contains the collections: "name" and "id". i store these collections by using insert command. now i need to add a new collection, lets say "address". can i simply…
Isaac
  • 21
  • 1
  • 4
2
votes
4 answers

select only two fields in mongodb using monk

My document has around 20 fields in it I want to select only 2 fields and ignore other fields I tried the below code as suggested here collection. find({}, { Name: 1, District: 1,_id:0},{limit:5}, function (e, docs) { res.json(docs); …
Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150
2
votes
1 answer

Using Cloud9 IDE - trying to connect to my mongodb

M using Cloud 9 IDE. I'm following this guide to learn: http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/ I have a folder called data which has my mongodb db. In my app.js, I have the following code: var mongo = require('mongodb'); var…
chintoo
  • 27
  • 6
2
votes
1 answer

not able to connect to mongodb hosted on remote server using monk

I am using node js, and for the backend i am using mongodb For connecting to DB, if i use the below line, it is fetching data var db = monk('localhost:27017/nodetest2'); But if i change that to below line, its not fetching the data var db =…
Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150
2
votes
4 answers

error in npm install inspite of changing the file Bson

using mongodb3.0, node 0.12.0, npm 2.5.1 on windows 7 integrale, I am trying to read and write data into my database, but i have this error in npm intsall! { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson:…
ch hach
  • 17
  • 1
  • 6
2
votes
0 answers

mongoDB query through NodeJS express app always returns null in mobile browser

I have this code that produces the desired effect in a desktop browser. var express = require('express'), http = require('http'), app = express(), mongo = require('mongodb'), ObjectId = require('mongodb').ObjectID, ISODate =…
ryechus
  • 787
  • 7
  • 17
2
votes
2 answers

MongoDB findAndModify not working with monk

I am trying to use findAndModify with the node.js mongodb module monk.This is the method that I am using,this throws a 500 error in my cmd: …
vamsiampolu
  • 6,328
  • 19
  • 82
  • 183
2
votes
4 answers

How can I connect my mongodb with the NODEjs app on Bluemix?

I have tried the below code for VCAP_SERVICES : if (process.env.VCAP_SERVICES) { var env = JSON.parse(process.env.VCAP_SERVICES); if (env['mongodb-2.2']) { var mongo = env['mongodb-2.2'][0]['credentials']; } } else { …
2
votes
2 answers

Trouble with PUT request using Node.js (express), Angular, and MongoDB

I'm stuck trying to figure out how to update my data to MongoDB (I'm using Monk with MongoDB, Node, Express, and Angular). I have no trouble with POST and DELETE, but can't figure out where I'm going wrong with PUT. Error I get: PUT…
Ben
  • 5,283
  • 9
  • 35
  • 44
2
votes
1 answer

how to start mongodb with Node.js using monk

I'm new to mongodb and nodeJS. Currently I've made a sample application using node.js, monk and mongodb. However to make it work, I have to open 2 cmd windows.The first one is go to mongodb folder, run: mongod --dbpath myprojectpath. The second is…
user1424258
  • 97
  • 1
  • 1
  • 10
2
votes
1 answer

Unable to assign a random string to _id field.

I am trying to save a document into mongodb using MONK drive. My object has a field called myid, which is a string of unknown length. I'm very inclined to use this ID as _id of my document but after I assign the value to _id field and save the…
Lee
  • 2,874
  • 3
  • 27
  • 51
2
votes
2 answers

In NodeJS, how to output results from mongodb with different field names?

I'm using nodejs to query mongodb and want to output json with customized field names. For example, original json from MongoDB maybe {id:1, text:"abc"} I'd like to output it as {ObjectID:1, DisplayText:"abc"}; I understand MongoDB has…
Lee
  • 2,874
  • 3
  • 27
  • 51
1
vote
1 answer

AttributeError: 'DataParallel' object has no attribute 'copy'

I am trying to resume training monkAI pytorch retinanet. I have loaded with .pt file instead of actual model. The changes are made in Monk_Object_Detection/5_pytorch_retinanet/lib/train_detector.py, check for '# change' in the places where its…
van
  • 15
  • 9
1 2
3
12 13