Comparing and updating items in MongoDB

I need help designing a restfull API to get items from orders DB and compare it against the available stock in the coffee’s DB coffee collection: orders collection: I am using the nodejs mongodb’s driver, not using mongoose. let coffee = {} let order = {} app.get(‘/orders/:coffeeid/:stock’, function(req, res) { db.collection(‘coffees’).find({‘name’: req.params.name}, (err, result) =>…

MongoDB Delete records with date field less than days from another field

I have a collection which stores application logs in documents: { “_id” : ObjectId(“5d92d5d01518a620ccaf015c”), “MessageType” : “ApplocationLog”, “FireAndForget” : true, “CreatedTimestamp” : ISODate(“2019-10-01T06:28:00.198+01:00”), “OriginReference” : “OriginReference”, “OriginName” : “OriginName”, “LogMessage” : “The log message”, “RetentionDays” : 1, “LogSeverity” : “Error”, “ApplicationUserContextId” : “User1”, “ApplicationUserContextName” : “User1Name”, “Exception” : null, “ErrorRelatedObjects” : null } I need…

What to save data in mongoDB and Schema is like bellow

var StatusSchema = new mongoose.Schema({ empName: { projectName: { type: String }, clientName: { type: String }, statusLastWeek: { type: String }, statusThisweek: { type: String }, planNextWeek: { type: String } } }); var Status = mongoose.model(‘Status’, StatusSchema); module.exports = Status; Description: Want save data in MongoDB, data schema is like above mentioned, save…

Connect multiple database in mongoDb using Nodejs runtime

I am trying to connect the multiple database with the API request. I tried to connect the DB using this code: const connectionString = `mongodb+srv://${process.env.DB_HOST}/${company.dbName}`; const client = new MongoClient(connectionString, { autoReconnect: true, reconnectTries: 60, reconnectInterval: 10000, useNewUrlParser: true, auth: { user: process.env.DB_USER, password: process.env.DB_PASS } }); await client.connect(); await client.db(company.dbName); I didn’t achieve any…

Unable to connect with mongodb from internal kubernetes cluster

I tried setting up mongodb via bitnami stable/mongodb helm chart, the helm chart installation command is as follows – helm install –name mongo –set mongodbRootPassword=mongo,mongodbUsername=mongo,mongodbPassword=mongo,mongodbDatabase=database stable/mongodb after creation of it, I am looking to connect my applications by following format of connection string mongodb://[user]:[password]@[service].[namespace].svc.cluster.local:27017/[db]?replicaSet=rs0&authSource=admin But I am getting error for this – failed to connect…

How can I figure out why MongoDB NodeJS driver isn’t returning results for valid queries for a single collection?

I am using MongoDB v3.2.7 for NodeJS v10.16.0. I created a MongoRepository base class that we’ve been using for a few years in Production. Sometimes in Development, I find quirky behavior where it won’t return any results for a specific collection. I used to think this was because I wasn’t closing the client between queries.…

GraphQL query returns empty array, but MongoDB query works

Edit: I found that the solution to the problem was setting the collection parameter. In mongoDB crypto_debug did not appear in plural form. Real big headache. const cryptoDebugModel = crypto_debug.model(“crypto_debug”, { name : String, dateOfIssue: String, error: String }, “crypto_debug”); I am having an issue where the graphQL query is returning an empty array and…