mongodb

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'

mongo count rows from an array of provided data

大城市里の小女人 提交于 2021-01-29 04:07:37
问题 I have collection like this: { "_id" : ObjectId("4d663451d1e7242c4b68e000"), "topic" : "abc", "subLevel" : { "id" : 1 } } { "_id" : ObjectId("4d6634514cb5cb2c4b69e000"), "topic" : "bce", "subLevel" : { "id" : 1 } } { "_id" : ObjectId("4d6634514cb5cb2c4b70e000"), "topic" : "bec", "subLevel" : { "id" : 2 } } { "_id" : ObjectId("4d6634514cb5cb2c4b70e000"), "topic" : "vvv", "subLevel" : { "id" : 3 } } and I need to count how many documents exist for provided subLevel.id list, for example if I

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

How to update string field in mongodb and manipulate string values?

拟墨画扇 提交于 2021-01-29 03:22:14
问题 I have a MongoDB collection with some documents that have a field called Personal.FirstName and another field call Personal.Surname. Some documents are messed up and have the persons first name and last name in both fields. For example there are some documents that have Personal.FirstName = 'John Doe' and Personal.Surname = 'John Doe'. I want to write a mongo update statement that will do the following: Find all of the documents that have a Personal section Find all of the documents where

How to update string field in mongodb and manipulate string values?

ぃ、小莉子 提交于 2021-01-29 03:17:44
问题 I have a MongoDB collection with some documents that have a field called Personal.FirstName and another field call Personal.Surname. Some documents are messed up and have the persons first name and last name in both fields. For example there are some documents that have Personal.FirstName = 'John Doe' and Personal.Surname = 'John Doe'. I want to write a mongo update statement that will do the following: Find all of the documents that have a Personal section Find all of the documents where

Flask & MongoDB - For Loop not working

戏子无情 提交于 2021-01-29 03:14:54
问题 Having this for Flask: example = mongo.db.example got_name = example.find({'name':1}) got_lastname = example.find({'lastname':1}) details = {'name' : got_name, 'lastname' : got_lastname} return render_template('blabla.html', details=details) Then the for loop using Jinja in my HTML (wanting it to be a table): {% for x in details} <tr> <td>{{ x.['name'] }}</td> <td>{{ x.['lastname'] }}</td> </tr> {% endfor %} But it won't work, it doesn't display anything in my table. I wrote this example

Cooperation MongoDB lazy loading with Jackson @JsonIgnore in SpringBoot Rest Controller

删除回忆录丶 提交于 2021-01-29 03:08:29
问题 I have written a RestController in my SpringBoot app. I am using a MongoDB as well. This is my entity: public class LocationEntity { @Id private String id; private String name; @DBRef(lazy = true) @JsonIgnore private UserEntity owner; private String description; @DBRef(lazy = true) private List<RoleEntity> roles; private Date date; public LocationEntity(String name, UserEntity owner, String description, List<RoleEntity> roles, Date date) { this.name = name; this.owner = owner; this