mongodb

Is there a way to update a document when date is expired in mongodb?

戏子无情 提交于 2021-01-29 10:47:33
问题 I have read some solutions and wonder if I can update (not delete) a document in mongodb if the date is expired after 2 days. Like this. date:2019-02-15 status:not expired After 2 days update the status into expired . Here is my code for posting a document. var bloodstock = new Bloodstock(); bloodstock.date = new Date(); bloodstock.status = "not expired"; bloodstock.save(function(err) {}); 回答1: Run a cron at daily midnight to compare the date. If the date exists 2 days update the status on

mongo db node.js some error with 'db' being undefined

你说的曾经没有我的故事 提交于 2021-01-29 10:36:15
问题 i am a newbiew and following a yt video https://www.youtube.com/watch?v=kwPWwczwi6c&list=PLsY8aWop1tAHigCqvxZ61XK3a8I509VRx&index=2 after creating a server.js file and running nodemon server.js file entered below var express = require("express"); var app = express(); var formidable = require("express-formidable"); app.use(formidable()); var mongodb = require("mongodb"); var mongoClient = mongodb.MongoClient; var ObjectId = mongodb.ObjectId; var http = require("http").createServer(app); var

Sort and Limit Embedded Document MongoDB

丶灬走出姿态 提交于 2021-01-29 10:09:39
问题 My MongoDB schema is built with embedded documents like this: { "_id" : ObjectId("5f0c64e4dd0a36b93c7deafa"), "name" : "Asd", "email" : "asd@neurondigital.tech", "password" : "$2b$12$66OTK8mSWELMF5YiF9HMUuHEeOVLI61aINjWs1Cmn1699lLJfz/7y", "auto_ml" : true, "notification" : true, "photo" : null, "tariff_id" : null, "city" : null, "sub_district" : null, "village" : null, "latitude" : null, "longitude" : null, "created_at" : ISODate("2020-07-13T20:43:00.871+0000"), "updated_at" : ISODate("2020

MongoDB Atlas initial high number of connections and storage

心已入冬 提交于 2021-01-29 10:02:23
问题 I just created a new empty cluster on mongoDB atlas. I chose the M20 cluster tier with 60GB storage limit. However, as soon as my cluster was created, it showed that there are 28 current connections on the server hosting the replica set (keeps increasing and decreasing, even reached 35). It also shows that the current disk space used is 6.3GB even though the cluster was just created and empty. Is this normal on Atlas? And why is the number this high? This bugs me as there is a limit on the

Solving relationships in Mongoose and GraphQL

↘锁芯ラ 提交于 2021-01-29 09:55:47
问题 So, I have this app that I'm starting and I'm going with MERNG stack using Apollo. I was doing research by reading blog posts and watching videos in order to have a better understanding of how GraphQL works (never actually worked with it). At some point, I started to see examples of relationships between db models such as "posts from a user". For example: import { model, Schema } from 'mongoose'; const postSchema = new Schema( { title: String, createdBy { type: Schema.Types.ObjectId, ref:

mongoose find and update removes the other fields

99封情书 提交于 2021-01-29 09:45:36
问题 I have schema like this: this.schema = new Schema({ userEmail: String environments: [ { envId: String, appPreference: String, language: String, timeZone: String, summaryNotificationSchedule: { timeOfTheDay: String } } ] }); Update request: { "envId": "u2", "appPreference": "put2", "timeZone": "gmt", "summaryNotificationSchedule.timeOfTheDay": "32400", } As you can see, I am not sending "language": "abc", in the update request and in the result I see the language field is removed. I want to

Mongodb is not updated properly from 4.2 to 4.4

杀马特。学长 韩版系。学妹 提交于 2021-01-29 09:40:31
问题 I was using mongodb 4.2.9 on ubuntu 18.04 I installed it with package manager. Now I to update it to 4.4 version used package manager following --> https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ instructions. Installation was ok but when I write mongod -version command it shows - db version v4.2.9 . I tried to re-install again it says mongodb-org is already the newest version (4.4.1). but mongod -version command it shows - db version v4.2.9 . How can I get rid of this

Can't connect to MongoDB container from other Docker container

寵の児 提交于 2021-01-29 09:38:42
问题 I have two containers linked together by Docker compose and I can successfully ping the container containing MongoDB from the one containing my node.js app using the hostname. However, when it comes to actually connecting to the database, node.js tells me the connection is refused. I am using Docker for Mac if that helps. mongoose.connect("mongodb://mongo", {server: {auto_reconnect: true}}).catch(error => { console.log("DB CONNECTION ERROR"); console.log(error) }); Here is my docker-compose

Unable to reach an external mongo db server from istio

只愿长相守 提交于 2021-01-29 09:37:22
问题 I am trying to implement service mesh using istio and envoy for a service which requires connecting to external mongodB server but for some reasons, my service is unable to reach the external mongodB server from istio proxy Below is the gateway and virtual service configuration for my service apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: gtreviews spec: selector: istio: ingressgateway servers: - port: number: 7890 name: http protocol: GRPC hosts: - "*" --- apiVersion:

How can I increment a counter variable in LoopBack 4 with a MongoDB datasource?

天大地大妈咪最大 提交于 2021-01-29 09:27:22
问题 I'm trying to convert my Nodejs Express app to Loopback 4 and I can't figure out how to increment a counter. In my Angular 9 app when a user clicks an icon a counter is incremented. This works perfectly in Express In Express const updateIconCount = async function (dataset, collection = 'icons') { let query = { _id: new ObjectId(dataset.id), userId: dataset.userId }; return await mongoController.update( collection, query, { $inc: { counter: 1 } }, function (err, res) { logAccess(res, 'debug',