Questions tagged [mongodb]

42789 questions
1

votes
1

answer
426

Views

Get error 'MongoResultException' when use aggregate in mongoDB

When i use aggregatein PHP, i get error: MongoResultException: localhost:27017: The 'cursor' option is required, except for aggregate with the explain argument I use mongoDB 3.6 and PHP 5.6 Please see the photo My Code: $dbconn = new MongoClient(); $c = $dbconn->selectDB('test')->selectCollection('...
noovin
1

votes
0

answer
88

Views

How do I get rid of BSON objects after a mapReduce?

I'm a complete beginner to map-reduce and relatively new with MongoDB. I am trying to perform a map-reduce on a collection (by the name Customers). My map function: var map = function() { emit(this.nationality, {edad: this.age, telefono: this.phone_number}); }; My reduce function: var reduce = funct...
1

votes
1

answer
92

Views

Java Spark: com.mongodb.spark.config.writeconfig issue

I am trying to connect with MongoDB via java spark connector and I am getting an error 'com.mongodb.spark.config.writeconfig', when I submit the jar and run the jar in spark shell. Here the error screenshot: Could you please help me to resolve this issue. I have tried this as well, but no success. $...
Tom Swayer
1

votes
1

answer
487

Views

create schema for imported csv in mongodb

i have a csv that looks like this: Number,Date,ClientName,ClientSurname,ClientAge,Option1,Option2 1,01/01/2015,John,Foo,24,30, using mongoimport i get { '_id':ObjectID(''), 'Number':1, 'date':'01/01/2015', 'ClientName':'John', 'ClientSurname':'Foo', 'ClientAge':24, 'Option1':30, 'Option2': '', } w...
doe
0

votes
1

answer
3k

Views

TypeError: path must be a string or Buffer MEAN stack

I am using Angular 5 on front-end, Node on back-end and Mongo as the database. Now I am trying to save an image to the database but constantly getting this error. I can't figure out if I'm making mistake on front or back because this is my first time working with files. I did my research but it poin...
JKshort
1

votes
0

answer
41

Views

How to make Spark Worker read data from local mongodb with mongodb-spark-connector?

I have got two 'mongodb' on two computers. And there is also a 'Spark Worker' on each computer. But when I run 'spark', it doesn't read data from its local 'mongodb'. Instead, it reads from one of them. Therefore, only got partial data. There is a page. https://docs.mongodb.com/spark-connector/maste...
BobXWu
1

votes
1

answer
34

Views

video is not fetching completly,

I want to fetch video from mongodb than it should play that video up to video size, but its playing only some second, i gave maxUploadSize is 20mb and maxInMemorySize also 20mb,but on the jsp page, its fetching only 1mb video even video size more than 1mb. I am not getting what to do, video should p...
Laxmi Prajapati
1

votes
2

answer
140

Views

What is the equivalent of PHP's mysqli_num_rows() in MongoDB?

Specification Database: MongoDB 3.4 Programming Language: PHP 7.1 Library: PHP library of MongoDB 1.2.0 Sample Code $result = $connection->db->collection->find($filter, $options); In MySQL, you do this: $number_of_rows = mysqli_num_rows($result); When trying things out and doing some research, I've...
Darren
1

votes
0

answer
21

Views

Migrate sharded mongo cluster from one cloud service to another

We are migrating mongodb (shared cluster architecture) from a cloud service to another. Let's call C1 (source) and C2 (dest). All of mongodb and mongos instances are bind with private ip (not using domain as expected) in C1. i stoped all instances of C1, copied to C2 successfully. But the new cluste...
William
1

votes
0

answer
24

Views

Why does mongo still throw error when I am handling error with if statement

I am deliberately trying to create duplicate key error by following code. let repoTemplate = new RepoTemplate({ name: templateName, //mongoose schema - unique creator: req.user.username, sheetsInfo: { calc: calcObj, result: resultsObj, data: dataObj, reference: referecneObj } }); repoTemplate....
forJ
1

votes
0

answer
44

Views

Rateable can't be blank(mongoid-letsrate,Mongoid)

When I try create new User(devise) I get this error: Rateable can't be blank(mongoid-letsrate,Mongoid) Mongoid::Errors::Validations: message: Validation of User failed. summary: The following errors were found: Rateable can't be blank resolution: Try persisting the document with valid data or remove...
1

votes
1

answer
408

Views

MongoDB can't start as a service

I am trying to run mongo as a service on CentOS 6, by using 'service mongod start'. However, I get the 'Failed' error I checked the log file and there is the following error at the end of it: IllegalOperation: Attempted to create a lock file on a read-only directory: /var/lib/mongo, terminating I h...
Bobonik
1

votes
0

answer
318

Views

How can we insert dictionary(json) in mongodb with Django using djongo library?

I am building REST API Using Django, MongoDB and djongo lib My requirement is, I have to store the dynamic JSON in MongoDB through djongo model. data={'name':'xyz','age':12} year=2017 month=10 class TestModel(models.Model): year = models.IntegerField() month = models.IntegerField() customer = 'I...
Ravinarayan Singh
1

votes
1

answer
602

Views

How do I access a remote aws lightsail mongodb over ssh tunnel

I have a Lightsail AWS instance up and running with a MEAN stack. I have an existing MEAN stack running on a different network. At the moment the node server.js connects to localhost for the mongo bit (on same machine) and all I want to do is replace the localhost with a connection to my mongo runni...
AEngineer
1

votes
2

answer
54

Views

How to remove an element from an array within Mongo

I'm completely stuck with Mongoose and remove method. I have a page with comments and form with a button Delete. My goal is to delete only that comment which was clicked. Below is my MongoDB file (By the way I use method override of the express library to handle both request post and delete). { '_i...
Ar2zee
1

votes
0

answer
429

Views

Sync NoSQL with SQL

Is there a way to sync NoSQL and SQL databases? My problem is: We have a software that uses MSSQL. We also have a mobile application that uses MongoDB. We want to sync data (on create/update) between those databases. Mostly from MongoDB to MSSQL. It is not a problem for us (if we have to) to use di...
italomarca
1

votes
2

answer
135

Views

Mongoose populate where

I have two models - M1 and M2. In M1 I have an array of M2 objects. I'm trying to create a query that will grab a bunch of M1 models but ONLY if a certain field in M2 matches the criteria I set. I've setup the models correctly (so M1 has an array of Schema.Types.ObjectId for M2). Ideally I'd want t...
user1157885
1

votes
1

answer
43

Views

Retrieve documents where birthday is today

I've the following collection called 'members': { '_id' : ObjectId('5a477681bbe5f506e68d29b7'), 'name' : 'mario', 'surname' : 'rossi', 'email' : '[email protected]', 'birth' : ISODate('1998-12-29T23:00:00Z'), 'fc' : null, 'expires' : ISODate('2018-12-29T23:00:00.183Z') }, { '_id' : ObjectId('5a47...
Raffaele
1

votes
1

answer
57

Views

Monk addToSet rewrites array

When I use Monk's addToSet in my route /upload-ajax, the array just rewrites itself with the first new element. Here is my code: const express = require('express'); const router = express.Router(); const debug = require('debug')('hackit:images'); const boom = require('boom'); const fs = require('fs'...
Mikita Melnikau
1

votes
0

answer
26

Views

Syntax reading high-volume data from the database and inserting in the array

We have a few million records in the mongoDB,now i want to put them in the array My problem is that,When I run the code, I encounter the following error Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 68 bytes) in I increase memory_limit to 2048 but not solved. Someo...
david
0

votes
0

answer
2

Views

res.redirect() searching but not loading

i'm trying to redirect a user to a page after checking his credentials through a post method. the thing is the page after the res.redirect function keeps trying to redirect but never does. app.post('/login', function (req, res) { MongoClient.connect(url, function(err, db){ if (err) throw err; var...
NeoK
1

votes
0

answer
107

Views

Accessing Object inside of Mongoose Field

I am trying to create a new user using mongoose and express. I am attempting to add a profile picture to the users Schema. I already have everything working, with the exception of the profile picture. I do not know how to access the buffer and contentType properties for the Schema.
Ellington Crevier
1

votes
1

answer
165

Views

How do I also delete the ObjectId from the parent element with mongoose?

So essentially what I have is a location index. Here is the location schema: var locationSchema = new mongoose.Schema({ name: String, gps: String, image: String, description: String, catches: [ { type: mongoose.Schema.Types.ObjectId, ref: 'Catch' } ] }); In this schema I also have 'catches' essenti...
Ronald Long
1

votes
1

answer
1.9k

Views

Node js error “process with a non-zero exit code”

I developing a REST API using node js and express with MongoDB. I have developed an endpoint to insert the user into DB and works fine. Now I have added the login function with jwt and now when I run my app and try to insert my user I receive this error: an app is listening on port 3000 (node:3650)...
user5858205
1

votes
1

answer
320

Views

how can I use ttl (time to live) on mongodb with collection.update?

I want to expire data in database ( its ok with expireAfterSeconds), but i want to use with collection.update>> data are always send data to database in real-time so TTL must be working on update data.. can i do that?? here is my code which i used for deleting a data from mongodb after specified tim...
Adnan Khan
1

votes
0

answer
52

Views

Providing an AppID, and AppSecret when building a REST API in NodeJS and MongoDB

I am building a REST API using NodeJS and MongoDB, and one of the features of REST API's that are made available for developers (e.g. Facebook, Twitter, Google etc) is to generate a unique AppID, and App Secret when developers register with your API on your site. What I would like to know is how do...
syedfa
1

votes
0

answer
310

Views

MongoDB - Problems with database design and statistical data calculation

I am currently facing a problem with MongoDB and that's probably due to my schema design, but I am unsure how to go about it. So basically I have this collection (mongoose Schema): const PlayerStatsCollection = { sportType: MongoId, player: MongoId, match: MongoId, team: MongoId, date: Date, league:...
Morphex
1

votes
0

answer
229

Views

Create view from multiple database

I learned about using db.siblingsDB and db.sisterDB. But I can't use both in creating a view from different databases. My example query I tried are: use 'database1' var users = db.getSiblingDB('database2').getCollection('User').find({}) db.runCommand({ 'create' : 'VW_User', 'viewOn' : users, 'pipeli...
trying...
1

votes
1

answer
1.2k

Views

How to fetch data from, mongodb to html form fields?

database name is test1 and collection name is feedbacks this is app.js I'm unable to get mongodb data in my html form field data is being inserted but i want to get intial values in my form help me out with this.since i am new to this i would like to have a simple explicit solution. var express = r...
sahil
1

votes
0

answer
370

Views

NodeJs process running out of memory on aws

I am running a nodeJS app on aws t2micro instance with Mongodb. This is how my index.js file on server looks like const db = require('./src/db'); const coins = require('./src/scrapers/populate-coins'); const scrape = require('./src/scrapers/index.js'); const settings = require('./src/trading/init-...
Gaurav
1

votes
3

answer
78

Views

Why MongoDB is fetching documents from disk after a sort even when the used index contains all fields on the query

Apparently MongoDB is fetching all documents from disk to be able to fulfill a query after a sort. To illustrate the issue we can insert the following documents with a progress and a date into a foo collection: db.foo.insert({ '_id' : 1, 'progress' : 'A', 'date' : ISODate('2017-12-01T07:52:40.831Z')...
1

votes
1

answer
403

Views

Define MongoDB Collection in REST API GET Request

I have data in 2 seperate collections stored in the same MongoDB database. Is there a way to define in the HTTP GET request query string from which collection the data should be retrieved. I use the following JS to process the query: const findDocuments = function(db, callback) { const collection =...
Sebs030
1

votes
1

answer
28

Views

Debug node mongo

How can I debug this error: It's simple code, but I don't know why I'm getting the error. module.exports.cliente = function(application, req, res){ var cl...
EFO
1

votes
1

answer
318

Views

Mongoose query returns empty array

I'm using Express to do a find operation in a Mongo collection and return the result. I know that there is data in the collection, but the result array comes back empty. I suspect that it's an issue with the schema, but can't figure out what. Thoughts? Route: const PlotStatus = require('../models/pl...
Boris K
1

votes
0

answer
51

Views

How to calculate distance from new coordinates in distancefile in GeoNear mongoDB

I am using mongo Db and I need to calculate distance from different coordinate other than provided in Near. How can I do that ` BsonDocument geoNear1 = new BsonDocument { { '$geoNear', new BsonDocument { { 'near', new BsonDocument { { 'type', 'Point' }, { 'coordinates', new BsonArray { -82.7469202,...
naveen chauhan
1

votes
1

answer
34

Views

How to update a MongoDB collections with an unknown number of possible fields using Mongoose

I want to update a mongodb collection without knowing exactly how many and which fields will be used to update. For example, if I have a user and they update information about them on different pages then it will not always be the same fields that are updated. Below is my current idea for how to app...
Brandon
1

votes
1

answer
225

Views

Mongodb: db undefined on connect

I am trying to access mongodb through native driver. When i use connect method in my remote method. I am getting connected successfully but i am getting 'undefined' as db object Purpose : Getting all fields name from collection. Activation.getUserFields = function (id, callbackFn) { Activation.app.d...
Ankur Akvaliya
1

votes
1

answer
142

Views

Error while in update query in MongoDB

What I'm trying to achieve in here is to update a given set of documents that contain a given set of fields, either one, another or both. I have two questions actually for this matter... Can MongoDB process fields that aren't present in the document being processed? Like what I'm trying to achieve h...
Lenny D.
1

votes
2

answer
76

Views

MongoDB Aggregation by Name and Different Time Interval

I've been looking for a solution for several days, and I can not get a result. Please, help me! I have a data in MongoDB: { name: 'apple', date: 2018-01-04T10:00:00.000Z, price: 100 } { name: 'apple', date: 2018-01-04T10:01:00.000Z, price: 101 } { name: 'apple', date: 2018-01-04T10:02:00.000Z, price...
COS
1

votes
0

answer
78

Views

How to insert data frame value into Mongodb in R

How to insert data frame value into Mongodb in R, I'm using below code to insert but i'm getting error val is my data frame. My Insert Query is mongo1$insert(val) But i'm getting Below error Error: No method asJSON S3 class: table
jhon peter

View additional questions