Questions tagged [mongodb]

28461 questions
0

votes
0

answer
3

Views

MongoDB aggregation - find string from array that also exists as a separate record

I am new to MongoDB and still learning. I have a problem in constructing an aggregation query. I have around 500 records in the format as below in my products collection: { "_id" : ObjectId("5948e51f7efe5b9e060a71a8"), "asin" : "0739040308", "categories" : [ [ "Movies & TV", "TV" ], [ "Musical Instr...
Kacper Wielki
0

votes
0

answer
3

Views

MONGO DB updating nested array

Below Array this Exisiting in DataBase and [{ name: 'Courier Received by Investor', value: true }, { name: 'Courier Sent By Investor', value: false }, { name: 'Signed CA-Doc received', value: false }, { name: 'Cheque/Payment Received', value: false }, { name: 'Cancelled Cheque Rece...
user8404712
1

votes
1

answer
1.1k

Views

Image storage performance on file system with Nodejs and Mongo

My Node.js application currently stores the uploaded images to the file system with the paths saved into a MongoDB database. Each document, maybe max 2000 in future, has between 4 and 10 images each. I don't believe I need to store the images in the database directly for my usage (I do not need to t...
adamK
1

votes
2

answer
171

Views

Select entries which doesn't have specified key

Assume, that I have bunch of entries in a document: db.document and some of them doesn't have some key, let's say name. So we have two types of entries - with and without name. { "_id" : ObjectId("4dea81a8bd2bb0323800002d"), "fetched_at" : ISODate("2013-08-02T17:41:30Z"), "keyword" : "110770", "n...
ciembor
1

votes
1

answer
4.1k

Views

Caching mongoose objects with Redis

Is it possible to cache, say, mongoose document obejcts in Redis, perhaps for implementing a write-back or write-through cache with timeout-based cache flush mechanisms? P.S.: I am familiar with mongoose-redis-cache, but I guess it supports only lean queries, which do not quite serve the purpose her...
ixaxaar
0

votes
0

answer
3

Views

Restore From Atlas Backup - Running C# WebAPI Services Fail To Reconnect

Scenario: Every Friday, we restore (using the atlas console) our production database down to our pre-production environments to keep the data in lower environments fresh. Effect: Our C# WebAPI services fail to connect after the restore is complete. Remediation: So far, we've solved the problem by re...
SamtecCraig
2

votes
0

answer
18

Views

How to connect securely to mongo docker container with mongoose through a node container for production?

Here is my docker-compose.production.yml. version: "3.7" services: ############################## # Back-End Container ############################## backend: container_name: mern_backend init: true environment: - MONGO_URI=mongodb://root_username:[email protected]_db:27017/mern_db?authSource=...
yaharga
1

votes
1

answer
1.7k

Views

Upserting to sharded MongoDB using mgo Error “full shard key must be in update object for collection:…”

Using the Labix mgo API for MongoDB, I am trying to perform an increment operation on a sharded collection. I am able to do this just fine on an unsharded collection using the usual mgo.Change struct, but when I try to do this on a sharded collection, I get the error: full shard key must be in updat...
Verran
1

votes
2

answer
4.7k

Views

Heroku Deploy Error: Cannot get Node App running after Deploy : Cannot find module '/app/web.js'

I have a node.js app using Express and MongoDB (mongoose). It runs perfectly fine locally. I deployed it to heroku seemingly without a problem, but when I try to actually launch the app it crashes. The heroku log says this: Error: Cannot find module '/app/web.js' I am new to this, so any help would...
user3416321
0

votes
0

answer
6

Views

Ruby on Rails, Can I get the current count of connections in Mongoid pool?

I have set min_pool_size to 100 in mongoid.yml but in mongo when running db.serverStatus().connections i only get 30. Is there a way to check how many connections I have in pool?
user793789
1

votes
3

answer
247

Views

MongoDb query and indexOnly=false

Executing the next query (with fields: {_id: 1}): { "namespace": "default", "active": true, "searchable": true, "type": "H", "keywords.extended": /^a/, } In a collection with 2.200.000 docs (matching namespace 200.000 docs) and documents like: { "active" : true, "keywords" : { "extended" : ["lo...
Wiliam
1

votes
2

answer
3k

Views

How to construct and pass bson document - Go lang?

I am using Go and mongoDB in my project and mgo is to connect to connect MongoDB. I am having following document this is to be inserted in the MongoDB { "_id" : ObjectId("53439d6b89e4d7ca240668e5"), "balanceamount" : 3, "type" : "reg", "authentication" : { "authmode" : "10", "authval" : "sd", "rec...
karthick
1

votes
1

answer
146

Views

Multiple updates in one document using mongoose

I want to update multiple values in a single document in one mongoose call. Is this possible? I have something similar to this: update = {$inc : { numShown : 1 }, $inc : { secondField.subField : 1 }}; options = {}; MyModel.findByIdAndUpdate(req._id, update, options, function(err){ if(err){ return c...
James B
1

votes
3

answer
616

Views

Log Data Analytics : Choice of Database [closed]

I am getting Log Data from various web applications in the following format: Session Timestamp Event Parameters 1 1 Started Session 1 2 Logged In Username:"user1" 2 3 Started Session 1 3...
Peeyush
1

votes
1

answer
806

Views

Can not find a record by it's _id in mongoDB

I want to get a record by its _id like this: db.user.find({_id : ObjectId("53a095aa4568cb1fef93f681")}) As you can see the record exists: I think my way is correct according to: Why am I unable to find a record by _id in mongodb how do I search for an object by its ObjectId in the console? Is it...
ehsan shirzadi
1

votes
1

answer
1.4k

Views

Self referencing of a schema not working

Following is my Schema - var mongoose = require('mongoose'); // Create Schema var userSchema = new mongoose.Schema({ name: String, email: String, created_by: { type: Schema.Types.ObjectId, ref: 'User'}, created_date: { type: Date, default: Date.now } }); // compile Schema into a model var User = mon...
Trialcoder
0

votes
0

answer
3

Views

MongoDB join by closest timestamp

Coming from using primarily PostgreSQL, I am new to MongoDB and am having trouble constructing complex queries in the required JSON format. To provide a simplified example - there are a number of cars with their own unique identifier vin. The cars ping when they are reserved, and when they are not...
the_darkside
0

votes
0

answer
5

Views

Monk - Why do my updates only work sometimes?

I am building a web application using the MEVN Stack. I am using the npm package 'Monk' to communicate with MongoDB. I have a route that inserts a new document into a collection, and when it gets called it is also supposed to update a document in another collection. However, this only works occasio...
Taylor Adam
1

votes
2

answer
3k

Views

Spring data mongodb aggregate function not working using 1.3.5-RELEASE of spring-data-mongodb

I have requirement to filter document in mongodb using spring data which contains nexted arrays of arrays. I am using following aggregation query on mongo shell and it is working fine. But when I am firing that through springdata aggregation operation, I am gettin empty response. Working mongo query...
Developer G
1

votes
1

answer
76

Views

MongoDB: Conditionally drop duplicates

I have a documents collection like so: { "word": "foo", "likes": 10, "dislikes": 1, }, { "word": "foo", "likes": 5, "dislikes": 9, }, The trouble is, my collection is riddled with similar documents (sharing the same word, but different data). I would like to remove these similar, almost duplicate en...
1

votes
1

answer
320

Views

Passing array name as parameters in mongoose

I'm using mongoose and I'm doing an update of my db by using findByIdAndUpdate() function. I'd like to push elements into different arrays present in my document. I have in my document different array with different names. May I pass as parameter the name array to this function or I should create di...
Mazzy
1

votes
3

answer
1.4k

Views

Convert any encoding to UTF 8 in Go

I'm downloading messages via IMAP. Next I'm adding parsed message into MongoDB. And I've a problem, because MongoDB support only UTF 8. And I wanna convert any encoding to UTF 8. Codes are various. How can I convert each string to UTF 8? I know, that I can convert to binary, but I have to have norma...
JakubKubera
1

votes
1

answer
2.4k

Views

What happen if I delete mongodb database files?

Here is my problem, I'm working with my own test VM on a data transformation project with Talend & Mongodb. Unfortunately I tried launching a Map/Reduce operation on a huge scale with apparently too few space available on disk. It crashed. (I loaded in a single collection data from a 2Go csv file, i...
Vincent Chalmel
0

votes
0

answer
14

Views

Mongoose not displaying data from mongoDB

i created a mongodb with a name userInfo with collection name "info" in the terminal and i created a schema in models/user_info.js.And i am not getting any values from the database at all. my userInfo db has name,studentId,dept My view engine is jade/pug I am trying to iterate and display the value...
e.T55
1

votes
1

answer
911

Views

Unable to get bluebird promise and mongoose's save() to work in node.js

Can anyone help me figure out how to rewrite the following working code in promise? I want to execute an insert query and then send the data back to clients via socket.js var func = require("functions") var mongoose = require('mongoose'); var mongo_models = require('./database/mongo_model')(mongoos...
RedGiant
1

votes
1

answer
1.9k

Views

Delete MongoDB document from Express, Node.js app

My index.jade file(my button which the users clicks to delete the document) is: a(href="/delete/#{booking.id}") Delete So far in my index.js file is: router.get('/delete/:id', function (req, res) { Booking.findOneAndDelete({ id: req.params.id }).remove().exec(); }); I also, tried: router.get('/delet...
TryingToLearnJS
1

votes
2

answer
6.2k

Views

Update single record in mongodb using express and node.js

I want to update a single record by _id in a collection in mongoDB. UPDATE: I changed the res to req (thanks!) and implemented the db.ObjectId() around the objectId I am passing in and now I get a 500 internal server error. "_id" : ObjectId("54d5296711436278137af74b"), "username" : "alex", "email"...
javascript Jenkins
1

votes
1

answer
50

Views

Efficiently page query results

I have mongo hooked up to a web application (Python/Pyramid Framework) and there is a large collection I want to display in the browser. Since it is very large, I only want to render 100 records at a time, allowing the user to click a "load more" button to retrieve the next 100 records. Pagination...
Matt H
1

votes
1

answer
2k

Views

Nodejs get user by id

Am using the MEAN stack for an app, i have users that i register and log in using satellizer everything work well. But when i try to get user by it's id i get nothing, i can do request to get all users but not by id. Note am using Ionicframework as a forntEnd framework. Here is the code of my back...
Ahmad Elmoualem
1

votes
2

answer
97

Views

MongoDB analytics collection - find users who did X having done Y

I have a big collection of event documents in a MongoDB collection. Fields in each document include: userId (database id, if user is logged in) visitorId (cookie id, always exists) eventType (the type of event the user has just done) One eventType in particular is of interest - the "purchase" type....
Chris Houghton
1

votes
2

answer
1.2k

Views

how to use mocking in unit testing in scala

hi i am new in Unit Testing and i want to test it using mock objects .i want to test whether data is successfully stored in mongoDB or not here is my code package models.RegularUserModels import models.UserModels.UserStatus._ // User will give information to Signup class DirectUser() extends Reg...
swaheed
1

votes
2

answer
870

Views

Use of $near to find nearest polygons of a certain point in mongodb

I have some polygons in a collection each as a document. I need to find the nearest polygons of a point in radius 50 KM. $near in mongo db will work for points. Is there any way to use $near to search nearest polygons of a certain point.
Amitabha Saha
0

votes
0

answer
2

Views

How to duplicate a record/document in MongoDB?

I want to duplicate my document based on a field in MongoDB. Refer to this documents below: a:1,b:2,c:3, a:2,b:2,c:3, a:1,b:4,c:3, a:2,b:2,c:3, a:1,b:5,c:6 So, i want duplicates of the documents where a=1. Output should be like this: a:1,b:2,c:3, a:2,b:2,c:3, a:1,b:4,c:3, a:2,b:2,c:3, a:1,b:5,c:6, a...
Nishant Ranjan
0

votes
0

answer
5

Views

How to convert excel 'AND' ,'OR ' condition to mongo conditions

I have some condition in excel format like this: AND(name = 'bob', age < 10) and it can be nested also. I want to convert it into mongo format for querying data: This should be translated into: Excel condition: AND(name 'bob', age < 10) equivalent mongo Condition: {$and: [{name: {$eq: 'bob'}},{age...
No one
1

votes
4

answer
2.5k

Views

Combination of multiple column unique mongoose nodejs

Objective To create uniqueness for two columns what i tried Here is my schema, var mongoose = require('mongoose'); // location table Schema var locationSchema = new mongoose.Schema({ locationId: { type: String, required: true }, stockingLocationId: { type: String, required: true}, parentStockingLoc...
1

votes
2

answer
4.2k

Views

Mongoose update not updating

I'm trying to update a document which has a specific ID with the current date/time but the below code is not resulting in the DB getting updated and no errors. Any help would be great, thanks. Schema: var MerchantShema = new Schema({ merchant_id: Number, merchant_aw_id: Number, merchant_name: String...
Geraint
1

votes
2

answer
384

Views

How mongoose population works

I want to use Mongoose Population and fetch some information from other collections. My models are: var mongoose = require('mongoose'); var Users = require('../users'); var schema = new mongoose.Schema({ book_name: String, book_publisher: String }); var book = mongoose.model('book', schema); module....
Fcoder
1

votes
2

answer
1.6k

Views

MongoDB aggregation like faceted search

Taking the example of the collection like: db.products.insert([ {"product_name": "Product 1", "filters": [{"name": "brand", "value": "Brand 1"}, {"name": "color", "value": "Color 1"}]}, {"product_name": "Product 2", "filters": [{"name": "brand", "value": "Brand 2"}, {"name": "color", "value": "Color...
1

votes
1

answer
418

Views

does a compound index in MongoDB improve multified match (not sorting)?

The documentation seems a bit unclear on that. 1)It clearly states that compound indexes DO improve performance of multi-field SORTING (order and direction dependant). 2) There is one phrase which makes me think it will also improve multi field MACH (sql analogy: where a=1 and b=2 and c
user1312695
1

votes
1

answer
467

Views

MongoDB $unwind field name conflict

Schema: {title: '', author: '', post: '', comments: [{author:'', comments: ''}]} Would there be 2 authors in the new document as a result of $unwind: "$comments"? How to give a new field name to comments.author?
lonelyloner

View additional questions