mongojs

MongoError: socket hang up

不想你离开。 提交于 2019-12-12 09:14:48
问题 I am trying to connect to the mongodb database on mongolabs(mlabs). I connect successfully when I run the code on my local computer and server.But When I run on my aws server I get this error database error { [MongoError: socket hang up] name: 'MongoError', message: 'socket hang up' } Code trial.js: var express = require('express'); var app = express(); var mongoose = require('mongoose'); var mongojs = require('mongojs'); var db = mongojs('mongodb://user:pass@ds01312192.mlab.com:133492

Integration testing with mongojs to cover database errors

≡放荡痞女 提交于 2019-12-12 06:08:45
问题 I'm working with mongojs and writing tests for mocha running coverage with istanbul . My issue is that I would like to include testing db errors. var mongojs = require('mongojs'); var db = mongojs.connect(/* connection string */); var collection = db.collection('test'); ... rpc.register('calendar.create', function(/*... */) { collection.update({...}, {...}, function (err, data) { if (err) { // this code should be tested return; } // all is good, this is usually covered }); }); the test looks

MongoDB: $push into an array based on a variable's contents

老子叫甜甜 提交于 2019-12-11 13:59:50
问题 I'm trying to $push an item into my record in MongoDB built on Node (using MongoJS ), like so: exports.saveToUser = function (req, res) { console.log("IN"); var user = req.params.user; var param = req.params.param; // equals "foo" var value = req.params.value; // equals "bar" console.log("Saving Data to User"); console.log(util.inspect(param, false, null)); db.users.update({"_id": ObjectId(user)}, {$push: {param:value}}, function (err, record) { if (err) { console.log("Lookup Error: " + err);

MongoDB: Insert multiple documents into collection with unique index even if some violate the index

让人想犯罪 __ 提交于 2019-12-11 07:55:58
问题 I am trying to insert an array of documents into a MongoDB collection. The collection has a unique index on one of the fields. I am inserting all the documents at once as such: const mongojs = require('mongojs'); const db = mongojs('mongodb://username:password@address.mlab.com:37230/database'); // documents is an array of documents db.items.insert(documents, (err, task) => { if (err) { console.log(err); } }) Now there is one document that violates the unique index and I receive this error:

MongoDB: Adding an array into an existing array

谁说我不能喝 提交于 2019-12-11 03:36:24
问题 I'm trying to add an "Instructors" array into an already existing "Camps" array. The hierarchical structure looks something like this: owner = { email : 'john.smith@gmail.com', password : 'mypassword', firstName : 'john', lastName : 'smith', camps : [ { name : 'cubs-killeen', location : 'killeen', manager : {name: 'joe black', email: '', password: ''}, instructors : [ { firstName : 'bill', lastName : 'jones', classes : [] }, { firstName : 'jill', lastName : 'jones', classes : [], }, ],

How to simulate an 'error' event on MongoDB

ⅰ亾dé卋堺 提交于 2019-12-11 02:25:30
问题 I'm trying to write a test case for a NoFlo component (written by a colleague) - where the component has a "connect" inPort and an "error" outPort like: var self = this; // a NoFlo Component var mongodb = null; self.inPorts.connect.on("data", function(uri) { mongodb = mongojs(uri); self.outPorts.connected.send(mongodb); mongodb.on("error", function(error) { self.outPorts.error.send(error); }); }); So based on this code pattern, how should I simulate an erroneous situation (in the test case)

MongoJS not returning data when searching with regular expressions

元气小坏坏 提交于 2019-12-08 04:53:27
问题 Node.js, mongojs, mongodb. I am searching through a list of skills using regular expressions. Here is my server code: var nconf = require('nconf'); var db = require('mongojs').connect(nconf.get('mongolab:connection'), ['skills', 'users']); app.get('/api/skill', function(req, res){ console.log('searching for ' + req.query['q']); var query = '{name: /' + req.query['q'] + '/i}'; console.log('query: ' + query); db.skills.find(query, function(err, data){ console.log('returning ' + JSON.stringify

How to get the array value and in structurized using Mongoose?

99封情书 提交于 2019-12-08 00:19:29
I am using MeanStack AngularJS . I stored the values into MongoDB like this: Data format "RoleName" : "Verify", "IsActive" : true, "UIList" : { "UiName": "One", "View" : false, "Edit" : false }, { "UiName": "Two", "View" : false, "Edit" : false }, { "UiName": "Three", "View" : false, "Edit" : false }, { "UiName": "Four", "View" : false, "Edit" : false }, { "UiName": "Five", "View" : false, "Edit" : false } Contoller $http.get('/Manage_Datashow').success(function (response) { $scope.Manage_Roleser = response; }); Server app.get('/Manage_Datashow', function (req, res) { db.New_Role.find(function

MongoDB and MongoJS - can't get runCommand to work for text queries

独自空忆成欢 提交于 2019-12-07 16:39:31
问题 My goal is to use MongoDB's (2.4.4) text command from Node. It works fine from the command line. Based on this previous SO issue: Equivalent to mongo shell db.collection.runCommand() in Node.js, I tried using MongoJS (0.7.17) but can't make it go. Here is the code: mongojs = require('mongojs'); var products = mongojs('localhost:27017/mydb').collection('products'); products.runCommand('text', {search: 'a'}, function (err, docs) { ... }); docs returns undefined and err is null. I can execute a

Mongodb text search multiple fields

你。 提交于 2019-12-06 07:59:51
问题 I have a mongodb document which looks like this: document title suburb id date And I want to add a search feature where people can search for documents via suburb and title. I am using the text search feature and I want something like this: var search = { $and : [ { $search:'melbourne' }, // Search in suburb { $search:'hello world' } // As well as in title ] }; db.ad.find(search).sort([['date', -1]]).limit(10).skip(0, callback); But the above code is not working. I have indexed both suburb