How to get a callback on MongoDB collection.find() in node.js

Published on

If you want your callback to provide results as an array of documents, change the find to: collection.find({‘_id’:o_id}, function(err, cursor){ cursor.toArray(callback); db.close();} ); Note that your function’s callback still needs to provide an err parameter so that the caller knows whether the query worked or not.

How to post an image directly to GridFS without storing it anywhere on the server?

Published on

Storing data stream from POST request in GridFS, express, mongoDB, node.js Using Postman (chrome ext.) to post a file, and I manage to store this post as a file using: req.pipe(fs.createWriteStream(‘./test.png’)); Also able to store directly to GridFS from a readStream when the readStream is created from a file on the server. (see code) I … Continue reading How to post an image directly to GridFS without storing it anywhere on the server?

How to Install MongoDB 3.2 on CentOS 7.x and RHEL 7.x

Published on

MongoDB is a scalable, Open source, high performance and document oriented NoSQL database. It is developed and supported by 10gen. NoSQL stats that MongoDB doesn’t use Tables and rows. MongoDB provide better performance as compared to other databases because it saves the data in JASON like documents along with dynamic schema. In this article we … Continue reading How to Install MongoDB 3.2 on CentOS 7.x and RHEL 7.x

Error: process.nextTick(function() { throw err; });

Published on

Getting the following error when i run my app.js. Unable to resolve the issue. /Applications/MAMP/htdocs/simplehacker/simplehacker-us/node_modules/mongodb/lib/utils.js:98 process.nextTick(function() { throw err; }); ^ WriteError({“code”:11000,”index”:0,”errmsg”:”E11000 duplicate key error index: instance.instancesmodels.$PublicDnsName_1 dup key: { : \”\” }”,”op”:{“PublicDnsName”:””,”instanceId”:”i-d9ff937a”,”reservationId”:”r-60e814b6″,”name”:”adhoc s1″,”region”:”us-east-1b”,”status”:”stopped”,”net_io”:””,”cpu_usage”:””,”_id”:”56a9c6d1e86e8bff040644cb”,”isInUse”:false,”__v”:0}}) at Function.MongoError.create…. Ans in the second line: WriteError: WriteError({ “code”: 11000, “index”: 0, “errmsg”: “E11000 duplicate key error index: instance.instancesmodels.$PublicDnsName_1 dup … Continue reading Error: process.nextTick(function() { throw err; });

How to find nearest locations around a route in MOngoDB Spring Data

Published on

The route information from the maps googleapi is broken down into steps that have a start location and end location with latitude/longitude coordinates. Computing the distance of the points in your model to all the start/end locations in the route would give you a measure of how far the point is from the route. The … Continue reading How to find nearest locations around a route in MOngoDB Spring Data

How to pass multiple parameters from the client through NodeJS to MongoDB

Published on

Let’s assume that you are making the following GET request GET /v1/myendpoint?key1=value1&key2=value2 You could create a javascript object from the querystring like the following {key1: ‘value1’, key2: ‘value2’} and use it in a mongo query var cursor = collection.find({key1: ‘value1’, key2: ‘value2’}) Updated solution based on the server side snippet var express = require(‘express’); var … Continue reading How to pass multiple parameters from the client through NodeJS to MongoDB

How to perform a bulk update of documents in MongoDB with Java

Published on

How to perform a bulk update of documents in MongoDB 3.2 with MongoDB Java Driver 3.2? Using the example in the manual on the new bulkWrite() API, consider the following test collection which contains the following documents: { “_id” : 1, “char” : “Brisbane”, “class” : “monk”, “lvl” : 4 }, { “_id” : 2, … Continue reading How to perform a bulk update of documents in MongoDB with Java