mongoose

update nested object in array Mongoose

两盒软妹~` 提交于 2021-01-29 05:20:27
问题 I would like the nested object with the id 5f0e14241f5ccb42d8742767 to be updated: { "_id": "5f0b33ab52a4e966c754d963", "make": "Toyota", "model": "Prius", "engine": "1.8", "insurances": [ { "yearlyPremium": { "$numberDecimal": "60.39" }, "_id": "5f0e14241f5ccb42d8742767", "startDate": "1970-01-19T09:31:15.550Z", "monthlyPremium": { "$numberDecimal": "5.49" }, "excess": 100 }, { "yearlyPremium": { "$numberDecimal": "71.39" }, "_id": "5f0e147c0340243eb03b5247", "startDate": "1970-01-19T09:31

Inserting an Image to MongoDB through Node.js

爷,独闯天下 提交于 2021-01-29 04:21:09
问题 I am having trouble inserting an image to MongoDB through node.js. My code is as follows: var express = require('express'), mongoose = require('mongoose'), fs = require('fs'), Schema = mongoose.Schema; app = express(), port = process.env.PORT || 3000; var imagePath = '~\images\image1.png'; mongoose.connect('mongodb://localhost/test'); var db = mongoose.connection; var contentSchema = new Schema({ _id: Schema.ObjectId, date: {type: Date, default: Date.now}, user_ip: Number, likes: Number,

How to solve “TypeError: callback.apply is not a function”?

荒凉一梦 提交于 2021-01-29 04:09:47
问题 I am doing a university project and I've read every post regarding my problem, but I am yet to find a solution. Maybe you can help me out. The code is the following: viewerObj.update({_id: currentIDViewerVar} , {minutesWatched: 5},{upsert:true} , function (err,result) { if (err) throw err; console.log("Viewer " + userNameVar + " gespeichert"); console.log("minsWatched" +minsWatched); }); I get the following error. I can't see what I am doing wrong. events.js:160 throw er; // Unhandled 'error'

How to solve “TypeError: callback.apply is not a function”?

眉间皱痕 提交于 2021-01-29 04:07:52
问题 I am doing a university project and I've read every post regarding my problem, but I am yet to find a solution. Maybe you can help me out. The code is the following: viewerObj.update({_id: currentIDViewerVar} , {minutesWatched: 5},{upsert:true} , function (err,result) { if (err) throw err; console.log("Viewer " + userNameVar + " gespeichert"); console.log("minsWatched" +minsWatched); }); I get the following error. I can't see what I am doing wrong. events.js:160 throw er; // Unhandled 'error'

Inserting an Image to MongoDB through Node.js

做~自己de王妃 提交于 2021-01-29 04:05:59
问题 I am having trouble inserting an image to MongoDB through node.js. My code is as follows: var express = require('express'), mongoose = require('mongoose'), fs = require('fs'), Schema = mongoose.Schema; app = express(), port = process.env.PORT || 3000; var imagePath = '~\images\image1.png'; mongoose.connect('mongodb://localhost/test'); var db = mongoose.connection; var contentSchema = new Schema({ _id: Schema.ObjectId, date: {type: Date, default: Date.now}, user_ip: Number, likes: Number,

Nodejs and Mongoose. Querying and updating object arrays inside object arrays

天大地大妈咪最大 提交于 2021-01-29 03:34:15
问题 I need to update a document using mongoose which contains an array of objects where each object within the array also contains an array of objects. Pseudo code for this would be something like: user.rooms[{where roomname = 'abc123'}].messages.push({message: 'hello', from: 'james'}) Where 'rooms' is an array of objects. And 'messages' is an array of objects which sits inside a room object which itself sits in the rooms array. I am confused as to how to build the query in terms of using $ in

Is it possible to have condition in mongoose populate

坚强是说给别人听的谎言 提交于 2021-01-29 03:29:36
问题 I have a sub document called services in a collection it contains serviceID and type . serviceID is referred to two collections internalservice and externalservice varies based on the type field. internalServices:[{ serviceID:ObjectId('0000000000000'), serviceDesc:'sweeping' }, { serviceID:ObjectId('0000000000000'), serviceDesc:'floor cleaning' }] externalServices:[{ serviceID:ObjectId('0000000000000'), serviceDesc:'painting' }, { serviceID:ObjectId('0000000000000'), serviceDesc:'white

Sort Keys in Response Object from Mongoose in ExpressJS and NodeJS

﹥>﹥吖頭↗ 提交于 2021-01-29 03:04:25
问题 I have been working on my own small API, so far everything works super fine, i just have a small cosmetic issue I can#t seem to find an answer to. I defined a schema like so in mongoose: const ArtistSchema = new Schema({ stageName: { type: String, unique: true, required: true, minlength: 3, maxlength: 255 }, realName: { type: String, unique: true, required: true, minlength: 5, maxlength: 255 }, birthday: { type: Date, required: true }, debutDate: { type: Date, required: true }, company: {

Mongoose script doesn't terminate properly

♀尐吖头ヾ 提交于 2021-01-28 23:41:44
问题 I have a node.js script that I want to run periodically that writes to mongodb using mongoose. It connects to mongodb, writes, and disconnects. The problem is that the script seems to hang sometimes. I have to manually terminate the script (ctrl+C). mongoose.connect(MONGODB_URL); var db = mongoose.connection; db.on('error', function(err) { console.log(err); }); db.on('open', function() { console.log('opened'); }); db.on('close', function() { console.log('closed'); }); Model.update(.....,

Mongoose script doesn't terminate properly

徘徊边缘 提交于 2021-01-28 23:36:37
问题 I have a node.js script that I want to run periodically that writes to mongodb using mongoose. It connects to mongodb, writes, and disconnects. The problem is that the script seems to hang sometimes. I have to manually terminate the script (ctrl+C). mongoose.connect(MONGODB_URL); var db = mongoose.connection; db.on('error', function(err) { console.log(err); }); db.on('open', function() { console.log('opened'); }); db.on('close', function() { console.log('closed'); }); Model.update(.....,