mongoose

user.setPassword is not a function - passport local mongoose

本秂侑毒 提交于 2021-01-27 19:06:21
问题 I am implementing a reset password feature on for the users of my website. However, it seems to throw this error when the user confirms new password at the reset.ejs page. The following steps are being performed correctly: Token sent on mail When clicked on token, new password page opens When user enters new password and confirm new password and hits the button to save the new password, the function in users.js user.setPassword does not work as the error is mentioned below. It is a built in

Can I access the positional $ operator in projection of findOneAndUpdate

孤街醉人 提交于 2021-01-27 15:31:51
问题 I have this query that works, but I want for the doc to only display network.stations.$ instead of the entire array. If I write fields: network.stations.$ , I get an error. Is there a way for the doc only to return a single element from [stations] ? Network.findOneAndUpdate({ "network.stations.id": req.params.station_Id }, { "network.stations.$.free_bikes": req.body.free_bikes }, { new: true, fields: "network.stations" }, (err, doc) => console.log(doc)) // I want doc to somehow point only to

Auto Increment Sequence in NestJs/Mongoose

陌路散爱 提交于 2021-01-27 14:40:47
问题 I'm migrating a NodeJs project to NestJs, this project uses MongoDB as back-end database and Mongoose as ODM. I was using the mongoose-sequence plugin to handle autoincrement sequences, however I'm facing troubles requiring the library under NestJs. The mongoose-sequence documentation explains how to import the library using CommonJS syntax as follows: const mongoose = require('mongoose') const AutoIncrementFactory = require('mongoose-sequence'); const connection = await mongoose

Sort by field in nested array with Mongoose.js

久未见 提交于 2021-01-27 13:10:25
问题 Given the data structure (based on my model) below how would I go about sorting the collection by cars.year in desc order with mongoose? So that first I find the max year in the cars array and then sort the collection by that. { "_id" : 1234, "dealershipName": "Eric’s Mongo Cars", "cars": [ {"year": 2013, "make": "10gen", "model": "MongoCar",}, {"year": 1985, "make": "DeLorean", "model": "DMC-12",} ] }, { "_id" : 1235, "dealershipName": "Eric’s Mongo Cars", "cars": [ {"year": 2015, "make":

Implicit async custom validators (custom validators that take 2 arguments) are deprecated in mongoose >= 4.9.0

无人久伴 提交于 2021-01-27 05:19:10
问题 I'm using mongoose 4.9.0. Whilst the code below works, I get a warning like the following: (node:24769) DeprecationWarning: Implicit async custom validators (custom validators that take 2 arguments) are deprecated in mongoose >= 4.9.0. See http://mongoosejs.com/docs/validation.html#async-custom-validators for more info. I suspect the error is coming from the model validators. const mongoose = require('mongoose'); const isEmail = require('validator/lib/isEmail'); const Schema = mongoose.Schema

Mongoose findoneandupdate returns updated document but not updated in database

ⅰ亾dé卋堺 提交于 2021-01-27 04:40:01
问题 The schema is correct, and these fields should be updating. So, I get partial data from one API call. And some from another. Which I'll note below. My schema: var coin = new Mongoose.Schema({ id: Number, rank: Number, source: String, symbol: String, name: String, cap: String, heat: Number, circulating_supply: Number, total_supply: Number, max_supply: Number, change: { hour: String, day: String }, quotes: { USD: { price: Number, volume_24h: Number, market_cap: Number, percent_change_1h: Number

Mongoose findoneandupdate returns updated document but not updated in database

人盡茶涼 提交于 2021-01-27 04:39:08
问题 The schema is correct, and these fields should be updating. So, I get partial data from one API call. And some from another. Which I'll note below. My schema: var coin = new Mongoose.Schema({ id: Number, rank: Number, source: String, symbol: String, name: String, cap: String, heat: Number, circulating_supply: Number, total_supply: Number, max_supply: Number, change: { hour: String, day: String }, quotes: { USD: { price: Number, volume_24h: Number, market_cap: Number, percent_change_1h: Number

Any way to get the modified IDS from mongodb's bulk operations using mongoose?

点点圈 提交于 2021-01-26 06:06:37
问题 let dbOperations = Edge.collection.initializeOrderedBulkOp() edges.forEach(edge => { dbOperations.find({_id: edge.id}).upsert().updateOne({ $set: { value: edge.value }, $setOnInsert: { _id: edge.id } }) }) dbOperations.execute() .then(result => { console.log(result.nModified) // This shows the number of edges that is actually modified console.log(result.getModifiedIds()) // This is what I want to achieve }) Any way to achieve this? 回答1: Well from one point of view the anwer is "no" and there

Mongoose schema set timestamp on nested document

橙三吉。 提交于 2021-01-24 11:43:45
问题 I have a schema that looks as follows: { "_id": "5073c76a23ce3abf0f000001", "asker": { "userId": "fooId", "firstName": "foo", "lastName": "bar", "points": "10", "aboutMe": "Something about me" }, "isBounty": false, "tags": ["mongodb", "nosql", "mongodb-query"], "title": "Is there merit to adding flat properties additional to a duplicate nested", "descriptionMd": "Question description", "offeredPoints": 10, "slug": "is-there-merit-to-adding-flat-properties-additional-to-a-duplicate-nested",

Mongoose schema set timestamp on nested document

半腔热情 提交于 2021-01-24 11:43:05
问题 I have a schema that looks as follows: { "_id": "5073c76a23ce3abf0f000001", "asker": { "userId": "fooId", "firstName": "foo", "lastName": "bar", "points": "10", "aboutMe": "Something about me" }, "isBounty": false, "tags": ["mongodb", "nosql", "mongodb-query"], "title": "Is there merit to adding flat properties additional to a duplicate nested", "descriptionMd": "Question description", "offeredPoints": 10, "slug": "is-there-merit-to-adding-flat-properties-additional-to-a-duplicate-nested",