mongodb

MongoDB-Community not starting on Mac and giving errors

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 06:34:20
问题 I am writing to inform that i had installed mongodb-community some time back using brew (High Sierra) and it was running. Then recently i upgraded and it doesn't seem to wire up. When i am running mongo in terminal, I am getting error: MongoDB shell version v4.4.0 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by

How to get percentage total of data with group by date in MongoDB

六眼飞鱼酱① 提交于 2021-02-11 05:57:55
问题 How to get percentage total of data with group by date in MongoDB ? Link example : https://mongoplayground.net/p/aNND4EPQhcb I have some collection structure like this { "_id" : ObjectId("5ccbb96706d1d47a4b2ced4b"), "date" : "2019-05-03T10:39:53.108Z", "id" : 166, "update_at" : "2019-05-03T10:45:36.208Z", "type" : "image" } { "_id" : ObjectId("5ccbb96706d1d47a4b2ced4c"), "date" : "2019-05-03T10:39:53.133Z", "id" : 166, "update_at" : "2019-05-03T10:45:36.208Z", "type" : "image" } { "_id" :

how to update a number field using another number field in MongoDB

会有一股神秘感。 提交于 2021-02-11 04:51:38
问题 Can MongoDB allow updating a number field using another number field in same document ? Let say I have a document like below : { "_id" : "1", "a" : 2, "b" : 3 } a and b fields are number fields(decimal,int...) my goal is update field b using field a How can I set b like b = 2*a . Is this possible ? 回答1: Note : On v 3.6 you don't have an option for direct update, You need to first read & process in code, then update. For v >= 4.2 you can do it in one call as .update() will accept aggregation

how to update a number field using another number field in MongoDB

亡梦爱人 提交于 2021-02-11 04:51:11
问题 Can MongoDB allow updating a number field using another number field in same document ? Let say I have a document like below : { "_id" : "1", "a" : 2, "b" : 3 } a and b fields are number fields(decimal,int...) my goal is update field b using field a How can I set b like b = 2*a . Is this possible ? 回答1: Note : On v 3.6 you don't have an option for direct update, You need to first read & process in code, then update. For v >= 4.2 you can do it in one call as .update() will accept aggregation

how to update a number field using another number field in MongoDB

允我心安 提交于 2021-02-11 04:51:07
问题 Can MongoDB allow updating a number field using another number field in same document ? Let say I have a document like below : { "_id" : "1", "a" : 2, "b" : 3 } a and b fields are number fields(decimal,int...) my goal is update field b using field a How can I set b like b = 2*a . Is this possible ? 回答1: Note : On v 3.6 you don't have an option for direct update, You need to first read & process in code, then update. For v >= 4.2 you can do it in one call as .update() will accept aggregation

How to modify value in array by position at aggregation framework

十年热恋 提交于 2021-02-11 04:28:13
问题 Let's say a have a simple document: { array: ["a", "b", "c", "d"] } How to modify the second value in aggregation ? With update it is very simple: db.collection.updateOne({}, { $set: { "array.1": "B" } } ) gives: { array: ["a", "B", "c", "d"] } In aggregation framework you can use this one: db.collection.aggregate([ { $set: { "array": { $map: { input: "$array", in: { $cond: { if: { $eq: [{ $indexOfArray: ["$array", "$$this"] }, 1] }, then: "B", else: "$$this" } } } } } } ]) However, this

Mongoose FindOneAndUpdate an embedded object and return parent

会有一股神秘感。 提交于 2021-02-11 04:21:56
问题 I'm having a similar problem laid out in this question, but I'm stumbling on a different aspect. I have an array of objects/subdocuments embedded within a document in my mongo database, schema like this.... const projectSchema = new mongoose.Schema({ name: { type: String }, ... stakeholders: [{ stakeholderTitle: { type: String, max: 150, required: [true, 'A stakeholder must have a title.'] }, ... }], what I need to do is update a particular embedded object based on the query, but I still need

Keep MongoDB connection open while running tests using mocha framework

天涯浪子 提交于 2021-02-10 22:52:30
问题 I'm using something akin to How to properly reuse connection to Mongodb across NodeJs application and modules to keep my mongoDB Connection open. This requires all the code to go into a MongoDB.connectDB(async (err) => {...} Block. How would I use this when writing Tests with Mocha. Do I have to use a separate Connection for every test? Like this? const MongoDB = require('../src/mongoUtil') // providing access to the mongo database var events = require('../src/events') // containing all my

Keep MongoDB connection open while running tests using mocha framework

寵の児 提交于 2021-02-10 22:52:22
问题 I'm using something akin to How to properly reuse connection to Mongodb across NodeJs application and modules to keep my mongoDB Connection open. This requires all the code to go into a MongoDB.connectDB(async (err) => {...} Block. How would I use this when writing Tests with Mocha. Do I have to use a separate Connection for every test? Like this? const MongoDB = require('../src/mongoUtil') // providing access to the mongo database var events = require('../src/events') // containing all my

Like search into MongoDB with Monk library

廉价感情. 提交于 2021-02-10 20:47:41
问题 I'm trying to do like search into mongodb with Javascript, but i havent yet figured it out how to do it. Any help is appreciated. I have a search parameter called "search" at request body (req.body.search). I would like find all programs which name contains that search criteria. Ie. "harry" would return " Harry Potter", "Potter Harry ", "How merry Harry Really is?" and other movies which contains harry in its name. exports.programs = function(db, req) { return function(req, res) { var